Skip to content

Commit

Permalink
Improve the README.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed May 15, 2024
1 parent 3033610 commit 3a5753c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
# Template repository for creating a custom Toit envelope

This repository can be used to create custom [envelopes](https://docs.toit.io/tutorials/containers)
for [Toit](https://toitlang.org/).

There are already many [pre-built envelopes](https://github.com/toitlang/envelopes) available, but
if you need to create a custom envelope, this repository can be used as a starting point.

## External services

See the [README-external-service.md](README-external-service.md) file for information on how to use external services.

## Setup

* Fork this repository (giving it a better name), and then detach the fork: https://support.github.com/request/fork
* Change the license to your license.
* Change the `TARGET` variable in the Makefile to the name of your chip. By default it is set to `esp32`.
* Run `make init`. This will copy some of the Toit files, depending on the target, to your repository.
### Prerequisites
* Make sure you have a complete build environment. See
- https://github.com/toitlang/toit, and
- https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html
- A good starting point is to run `install.sh` from the `toit/third_party/esp-idf` folder.

The [ci.yml](.github/workflows/ci.yml) file uses Toit's setup action to install all prerequisites
on a GitHub runner. You can use this as a reference for setting up your own environment.

## Makefile targets
### Initial setup

* Duplicate this repository, following
[GitHub's instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository).
If you forked it, you can also detach the fork: https://support.github.com/request/fork
* Change the license to your license.
* Change the `TARGET` variable in the Makefile to the name of your chip. By default it is set to `esp32`.
* Run `make init`. This will copy some of the Toit files, depending on the target, to your repository.

### Configuration
* Adjust or remove the C components in the `components` folder.
* Run `make menuconfig` to configure the build.
* Adjust the [ci.yml](.github/workflows/ci.yml) file to match your setup. Typically, you don't need
to compile on Windows or macOS.

### Build
* Run `make` to build the envelope. It should end up with a `build/esp32/firmware.envelope`.

## Makefile targets
- `make` or `make all` - Build the envelope.
- `make init` - Initialize after cloning. See the Setup section above.
- `make menuconfig` - Runs the ESP-IDF menuconfig tool in the build-root. Also creates the `sdkconfig.defaults` file.
Expand Down
12 changes: 6 additions & 6 deletions components/echo/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static toit_err_t on_created(void* user_data, toit_msg_context_t* context) {
/// @param data The data of the message.
/// @param length The length of the message.
/// @return TOIT_ERR_SUCCESS. The only allowed return value.
static toit_err_t on_message(void* user_data, int sender, void* data, int length) {
static toit_err_t on_message(void* user_data, int sender, uint8_t* data, int length) {
echo_service_t* echo_service = (echo_service_t*)user_data;
toit_msg_context_t* context = echo_service->msg_context;
if (toit_msg_notify(context, sender, data, length, true) != TOIT_ERR_SUCCESS) {
Expand All @@ -58,7 +58,7 @@ static toit_err_t on_message(void* user_data, int sender, void* data, int length
/// @param data The data of the request.
/// @param length The length of the request.
/// @return TOIT_ERR_SUCCESS. The only allowed return value.
static toit_err_t on_rpc_request(void* user_data, int sender, int function, toit_msg_request_handle_t handle, void* data, int length) {
static toit_err_t on_rpc_request(void* user_data, int sender, int function, toit_msg_request_handle_t handle, uint8_t* data, int length) {
if (toit_msg_request_reply(handle, data, length, true) != TOIT_ERR_SUCCESS) {
printf("unable to reply\n");
}
Expand All @@ -81,10 +81,10 @@ static void __attribute__((constructor)) init() {
echo_service_t* echo_service = (echo_service_t*)malloc(sizeof(echo_service_t));
echo_service->msg_context = NULL;
toit_msg_cbs_t cbs = {
.on_created = &on_created,
.on_message = &on_message,
.on_rpc_request = &on_rpc_request,
.on_removed = &on_removed,
.on_created = on_created,
.on_message = on_message,
.on_rpc_request = on_rpc_request,
.on_removed = on_removed,
};
toit_msg_add_handler("toitlang.org/demo-echo", echo_service, cbs);
}

0 comments on commit 3a5753c

Please sign in to comment.