Skip to content

Commit

Permalink
Make prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Jun 16, 2024
1 parent decae6a commit 72b3edd
Show file tree
Hide file tree
Showing 23 changed files with 583 additions and 580 deletions.
2 changes: 0 additions & 2 deletions docs/hexpansions/creating-hexpansions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ If you're laser-cutting a hexpansion out of plastic, note that _cast_ acrylic sh

There are some [example 3D printable STL files](https://www.printables.com/model/826094-emf-tildagon-hexpansion-template) and a [FreeCAD template](https://www.printables.com/model/881594-tildagon-hexpansion-freecad-templates-and-nfc) on Printables, which may be useful as a starting point for prototyping.


!!! tip "Templates for PCB Hexpansions"

There is a [sample KiCAD hexpansion project](https://github.com/emfcamp/badge-2024-hardware/tree/main/hexpansion), which is the easiest way of getting started making a Hexpansion PCB.


## Shape and size

To fit into the slot, the hexpansion has to have a tab sticking out that is **9.2mm** wide and **6.5mm** long. That tab is 17.75mm away from the board edge.
Expand Down
83 changes: 42 additions & 41 deletions docs/hexpansions/eeprom.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,63 @@ If you want your EEPROM-equipped hexpansion to do something automatically, you n
2. Clone the [`badge-2024-software`](https://github.com/emfcamp/badge-2024-software) repo and `cd` into it.
3. Modify the port in the [`prepare_eeprom.py`](https://github.com/emfcamp/badge-2024-software/blob/main/modules/scripts/prepare_eeprom.py) script:

```python
# Set up i2c
port = 2 # <<-- Customize!!
i2c = I2C(port)
```
```python
# Set up i2c
port = 2 # <<-- Customize!!
i2c = I2C(port)
```

4. Adjust the header information as you desire:

```python
# Fill in your desired header info here:
header = HexpansionHeader(
manifest_version="2024",
fs_offset=32,
eeprom_page_size=16,
eeprom_total_size=1024 * (16 // 8) // 8,
vid=0xCA75,
pid=0x1337,
unique_id=0x0,
friendly_name="Flopagon",
)
```

For more information see [EEPROM format](#eeprom-format).
```python
# Fill in your desired header info here:
header = HexpansionHeader(
manifest_version="2024",
fs_offset=32,
eeprom_page_size=16,
eeprom_total_size=1024 * (16 // 8) // 8,
vid=0xCA75,
pid=0x1337,
unique_id=0x0,
friendly_name="Flopagon",
)
```

For more information see [EEPROM format](#eeprom-format).

5. The following [`mpremote`](https://docs.micropython.org/en/latest/reference/mpremote.html) command mounts the `modules` directory and runs the `prepare_eeprom.py` script from the locally mounted directory. The `prepare_eeprom.py` script flashes a header to the first page of the EEPROM:

```sh
mpremote mount modules + run modules/scripts/prepare_eeprom.py
```
```sh
mpremote mount modules + run modules/scripts/prepare_eeprom.py
```

`mpremote` should automatically detect the port the board is plugged into. If it doesn't, manually specify the port. For more information see the [`mpremote` reference docs](https://docs.micropython.org/en/latest/reference/mpremote.html#shortcuts).
`mpremote` should automatically detect the port the board is plugged into. If it doesn't, manually specify the port. For more information see the [`mpremote` reference docs](https://docs.micropython.org/en/latest/reference/mpremote.html#shortcuts).

!!! note "Failed to decode header?"
!!! note "Failed to decode header?"

If you are receiving this error, try to change this code
If you are receiving this error, try to change this code

```python
write_header(
port, header, addr=addr, addr_len=addr_len, page_size=header.eeprom_page_size
)
```
```python
write_header(
port, header, addr=addr, addr_len=addr_len, page_size=header.eeprom_page_size
)
```

to
to

```python
i2c.writeto(addr, bytes([0, 0]) + header.to_bytes())
```
```python
i2c.writeto(addr, bytes([0, 0]) + header.to_bytes())
```

and run the command again.
and run the command again.

6. The following [`mpremote`](https://docs.micropython.org/en/latest/reference/mpremote.html) command mounts the `modules` directory and runs the `mount_hexpansion` script to mount the storage on your hexpansion, and then copies your app file from the provided location to `/hexpansion_1/app.py`:

```sh
mpremote mount modules + run modules/scripts/mount_hexpansions.py + cp path/to/your/app.py :/hexpansion_{YOUR-HEXPANSION-PORT-NUMBER}/app.py
# For example:
# mpremote mount modules + run modules/scripts/mount_hexpansions.py + cp sim/apps/snake/app.py :/hexpansion_1/app.py
```
```sh
mpremote mount modules + run modules/scripts/mount_hexpansions.py + cp path/to/your/app.py :/hexpansion_{YOUR-HEXPANSION-PORT-NUMBER}/app.py
# For example:
# mpremote mount modules + run modules/scripts/mount_hexpansions.py + cp sim/apps/snake/app.py :/hexpansion_1/app.py
```

## EEPROM format

Expand Down Expand Up @@ -100,6 +100,7 @@ The header is 32 bytes long and contains the following values:
- Friendly name (offset 22, length 9, padded with 0x00)
- This is an ASCII string containing a name to be displayed in menus and prompts so that users can identify the hexpansion. It can contain up to nine characters, and unused characters should be set to 0x00.
- Checksum (offset 31, length 1)

- This is a checksum calculated by the following algorithm:

1. Start with a variable S with the value 0x55
Expand Down
21 changes: 11 additions & 10 deletions docs/hexpansions/writing-hexpansion-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ There are three options for your hexpansion app:

1. Your hexpansion has an EEPROM and your app will be written to it and run from it.
2. Your hexpansion has an EEPROM, but your app is going to be downloaded from the app store and run separately.
3. Your hexpansion does not have an EEPROM, so your app will be downloaded from the app store and run separately.
3. Your hexpansion does not have an EEPROM, so your app will be downloaded from the app store and run separately.

Which aproach you use is dependent on the hexpansion you're writing an app for and your own personal preference. If your app is likely to be so large that it'll exceed the space on the EEPROM, you might want to explore cross-compiling your app using [mpy-cross](https://pypi.org/project/mpy-cross/) to reduce its size. If your app is still too large, option 2 is your best bet.

Expand Down Expand Up @@ -200,31 +200,32 @@ Below is an example of how you find which port your hexpansion is plugged in to
__app_export__ = ExampleApp
```


In all of these examples, the `HexpansionConfig` object is used to provide information about the port your hexpansion is plugged into.

## The HexpansionConfig class

The `HexpansionConfig` object that you get after following the examples is where the magic all happens. It allows you to access the following:

| Object | Description | Example Usage |
| ------ | ----------- | --------- |
| `HexpansionConfig.port` | The port number your hexpansion is connected to. | |
| `HexpansionConfig.pin[]` | A list of 4 `Pin` objects. These are the high-speed, direct GPIO pins for this hexpansion port. | [See MicroPython Docs](https://docs.micropython.org/en/latest/library/machine.Pin.html) |
| `HexpansionConfig.ls_pin[]` | A list of 5 `ePin` objects for this hexpansion port. These are the emulated, low-speed GPIO pins for this hexpansion port. | [See eGPIO](../tildagon-apps/reference/badge-hardware.md#egpio) |
| `HexpansionConfig.i2c` | The dedicated `I2C` object for this hexpansion port. | [See I2C](../tildagon-apps/reference/badge-hardware.md#i2c) |
| Object | Description | Example Usage |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `HexpansionConfig.port` | The port number your hexpansion is connected to. | |
| `HexpansionConfig.pin[]` | A list of 4 `Pin` objects. These are the high-speed, direct GPIO pins for this hexpansion port. | [See MicroPython Docs](https://docs.micropython.org/en/latest/library/machine.Pin.html) |
| `HexpansionConfig.ls_pin[]` | A list of 5 `ePin` objects for this hexpansion port. These are the emulated, low-speed GPIO pins for this hexpansion port. | [See eGPIO](../tildagon-apps/reference/badge-hardware.md#egpio) |
| `HexpansionConfig.i2c` | The dedicated `I2C` object for this hexpansion port. | [See I2C](../tildagon-apps/reference/badge-hardware.md#i2c) |

### Pin vs ePin

Hexpansion ports have two types of GPIO pins - `Pin` objects and `ePin` objects. The difference between these is important, and would have been a key design consideration for your hexpansion.
Hexpansion ports have two types of GPIO pins - `Pin` objects and `ePin` objects. The difference between these is important, and would have been a key design consideration for your hexpansion.

`Pin` objects are regular high speed GPIO pins. These are available through `HexpansionConfig.pin[]`. They are connected directly to the GPIO pins of the ESP32-S3, and can be controlled using the standard MicroPython `Pin` API. These pins are available for routing any of the unused peripherals from the ESP32-S3 to, so you could configure them as an `SPI` bus, use the `RMT` peripheral, be a `PWM` output etc. You can also use them for any other GPIO tasks where switching speed is important, such as communicating on an arbitrary protocol. Don't try to source or sink too much current from these pins - the usual rules for connecting things to microcontroller pins apply here.

!!! note "Using the ADC"
If you want to use the analogue to digital converter (`ADC`) peripheral of the ESP32-S3, your hexpansion needs to be in port 4, 5 or 6. Your detection code should be written to check for this and act accordingly. See [electrical interface](creating-hexpansions.md#electrical-interface).
If you want to use the analogue to digital converter (`ADC`) peripheral of the ESP32-S3, your hexpansion needs to be in port 4, 5 or 6. Your detection code should be written to check for this and act accordingly. See [electrical interface](creating-hexpansions.md#electrical-interface).

<!-- markdown-link-check-disable -->

`ePin` objects are lower speed, emulated GPIOs. These are not connected directly to the ESP32-S3, but are instead connected via a [GPIO expander IC](https://github.com/emfcamp/badge-2024-hardware/blob/main/datasheets/AW9523%2BEnglish%2BDatasheet.pdf) over an I2C bus. Because the badge has to talk to the GPIO expander to change the state of the pins, these pins cannot be switched as fast as the `Pin` objects, but are still plenty fast for indicator LEDs, input buttons, or anything that requires a simple high/low logic level. The GPIO expander IC also provides a constant current LED driver, so you can connect LEDs directly to these pins and control their brightness in hardware. `ePin` objects use a different API to `Pin` objects.

<!-- markdown-link-check-enable -->

## Further development
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Unlike in previous years, [Electromagnetic Field](https://www.emfcamp.org/) is t
## Hexpansions

<!--hexpansions-definition-start-->

Hexpansions are accessories that plug into the badge's expansion connectors. Almost anything can be a hexpansion - the simplest hexpansion is just a piece of 1mm card cut into the right hexagonal shape. Here are some community examples: (1)
{ .annotate }

Expand Down
Loading

0 comments on commit 72b3edd

Please sign in to comment.