| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,55 @@ | ||
| #include "shared-bindings/board/__init__.h" | ||
|
|
||
| #include "supervisor/shared/board_busses.h" | ||
|
|
||
| STATIC const mp_rom_map_elem_t board_module_globals_table[] = { | ||
| { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) }, | ||
| { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_05) }, | ||
| { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_30) }, | ||
| { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_28) }, | ||
| { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_02) }, | ||
| { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_03) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_31) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_P0_29) }, | ||
| { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_P0_29) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_SWITCH), MP_ROM_PTR(&pin_P1_02) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, | ||
| { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P0_10) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_08) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P0_07) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P0_26) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P0_27) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_06) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_08) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P1_09) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_16) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_14) }, | ||
| { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_13) }, | ||
| { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_15) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_25) }, | ||
| { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_24) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, | ||
| { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_12) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P1_15) }, | ||
| { MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_P1_15) }, | ||
| { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_P1_15) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_BLUE_LED), MP_ROM_PTR(&pin_P1_10) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, | ||
| { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, | ||
| { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, | ||
| }; | ||
|
|
||
| MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # MakerDiary NRF52840 MDK USB Dongle | ||
|
|
||
| Refer to [The makerdiary Github repo](https://github.com/makerdiary/nrf52840-mdk-usb-dongle) | ||
| or [The nrf52840-mdk-usb-dongle wiki](https://wiki.makerdiary.com/nrf52840-mdk-usb-dongle/) | ||
| for more details about the device. | ||
|
|
||
| This is pretty much just the nRF52840 with a useful number of pins exposed for | ||
| your pleasure along with one RGB LED and an onboard antenna in a USB stick form | ||
| factor with room for headers on the sides. | ||
|
|
||
| Note that all three LEDs on this device are wired through sinks, not sources, | ||
| so flip your boolean expectations when dealing with `DigitalInOut` or `PWMOut` | ||
| on this device -- | ||
| `led.value = True` or `led.duty_cycle = 0xffff` turns the LED off! | ||
|
|
||
| The onboard button is hard wired to the Reset pin so you cannot use it yourself. | ||
|
|
||
| ## Installing CircuitPython submodules | ||
|
|
||
| Before you can build, you will need to run the following commands once, which | ||
| will install the submodules that are part of the CircuitPython ecosystem, and | ||
| build the `mpy-cross` tool: | ||
|
|
||
| ``` | ||
| $ cd circuitpython | ||
| $ git submodule update --init | ||
| $ make -C mpy-cross | ||
| ``` | ||
|
|
||
| ## Note about bootloaders | ||
|
|
||
| While most Adafruit devices come with (or can easily be flashed with) an | ||
| Adafruit-provided bootloader (supporting niceties like UF2 flashing), this | ||
| board comes with one that supports DFU via nrfutil. If you ever need to | ||
| restore the DFU bootloader via a SWD debugger, use | ||
| [the nRF52 open bootloader hex file](https://github.com/makerdiary/nrf52840-mdk-usb-dongle/tree/master/firmware/open_bootloader). | ||
|
|
||
| ## Building and Flashing CircuitPython | ||
|
|
||
| ``` | ||
| $ cd ports/nrf | ||
| ``` | ||
|
|
||
| ### Build CircuitPython for the MDK USB Dongle | ||
|
|
||
| ``` | ||
| make BOARD=makerdiary_nrf52840_mdk_usb_dongle SD=s140 V=1 -j4 hex | ||
| ``` | ||
|
|
||
| This should produce a `build-makerdiary_nrf52840_mdk_usb_dongle-s140/firmware.hex` file. | ||
|
|
||
| ### Install nrfutil | ||
|
|
||
| You'll need to have [nrfutil](https://pypi.org/project/nrfutil/) installed as | ||
| appropriate for your system. | ||
| As of 2019-01, _nrfutil still requires Python 2.7_... ugh! | ||
|
|
||
| ### Flash the nRF52 Radio Soft Device | ||
|
|
||
| Build a DFU package from the softdevice hex file and flash it: | ||
|
|
||
| ```sh | ||
| nrfutil pkg generate --hw-version 52 --sd-req 0x00 --sd-id 0xAE --softdevice bluetooth/s140_nrf52_6.1.0/s140_nrf52_6.1.0_softdevice.hex dfu_sd140-6.1.0.zip | ||
| nrfutil dfu usb-serial -pkg dfu_sd140-6.1.0.zip -p /dev/tty.usbmodemABRACADBRA # likely /dev/ttyACM0 on Linux | ||
| ``` | ||
|
|
||
| Note that the `--sd=id 0xAE` comes from the Nordic nRF52 manual for SoftDevice | ||
| 6.1.0. When the SoftDevice is changed, read the Nordic manual to find the | ||
| correct value and use it on all of the `nrfutil pkg generate` commands. | ||
|
|
||
| `/dev/tty.usbmodem*` is a macOS name. On Linux it'll likely be `/dev/ttyACM*`. On Windows probably a COM port. | ||
|
|
||
| ### Flash CircuitPython | ||
|
|
||
| Build a DFU package from the hex application file and flash it: | ||
|
|
||
| ``` | ||
| nrfutil pkg generate --sd-req 0xAE --application build-makerdiary_nrf52840_mdk_usb_dongle-s140/firmware.hex --hw-version 52 --application-version 1 dfu_circuitpython.zip | ||
| nrfutil dfu usb-serial -pkg dfu_circuitpython.zip -p /dev/tty.usbmodemABRACADBRA | ||
| ``` | ||
|
|
||
| I'm not sure if `--application-version 1` is actually meaningful or required. | ||
|
|
||
| After this, your device should be up and running CircuitPython. When it | ||
| resets, you'll see the CIRCUITPY USB filesystem and a new console usb modem | ||
| serial port show up. | ||
|
|
||
| ``` | ||
| Adafruit CircuitPython 4.0.0-alpha.5-139-g10ceb6716 on 2019-01-14; MakerDiary nRF52840 MDK USB Dongle with nRF52840 | ||
| >>> | ||
| ``` | ||
|
|
||
| ### TODO items | ||
|
|
||
| * Update the Makefile to do the above DFU .zip building and nrfutil flashing. | ||
| * Create a UF2 bootloader for this. It is already a USB stick form factor, it deserves to behave like one. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,6 @@ | |
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include "boards/board.h" | ||
|
|
||
| void board_init(void) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| USB_VID = 0x239A | ||
| USB_PID = 0x802A | ||
| USB_PRODUCT = "nRF52840-MDK-Dongle" | ||
| USB_MANUFACTURER = "makerdiary" | ||
|
|
||
| MCU_SERIES = m4 | ||
| MCU_VARIANT = nrf52 | ||
| MCU_SUB_VARIANT = nrf52840 | ||
| MCU_CHIP = nrf52840 | ||
| SD ?= s140 | ||
| SOFTDEV_VERSION ?= 6.1.0 | ||
|
|
||
| BOOT_SETTING_ADDR = 0xFF000 | ||
| BOOT_FILE = boards/$(BOARD)/bootloader/$(SOFTDEV_VERSION)/$(BOARD)_bootloader_$(SOFTDEV_VERSION)_s140 | ||
|
|
||
| ifeq ($(SD),) | ||
| LD_FILE = boards/nrf52840_1M_256k.ld | ||
| else | ||
| LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld | ||
| endif | ||
|
|
||
| NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include "shared-bindings/board/__init__.h" | ||
|
|
||
| #include "supervisor/shared/board_busses.h" | ||
|
|
||
| STATIC const mp_rom_map_elem_t board_module_globals_table[] = { | ||
| { MP_ROM_QSTR(MP_QSTR_AIN0), MP_ROM_PTR(&pin_P0_02) }, | ||
| { MP_ROM_QSTR(MP_QSTR_AIN1), MP_ROM_PTR(&pin_P0_03) }, | ||
| { MP_ROM_QSTR(MP_QSTR_AIN2), MP_ROM_PTR(&pin_P0_04) }, | ||
| { MP_ROM_QSTR(MP_QSTR_AIN3), MP_ROM_PTR(&pin_P0_05) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) }, // User must connect manually. | ||
| { MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) }, // User must connect manually. | ||
|
|
||
| // Not defining the NFC names until CircuitPython supports NFC. | ||
| // { MP_ROM_QSTR(MP_QSTR_NFC1), MP_ROM_PTR(&pin_P0_09) }, | ||
| // { MP_ROM_QSTR(MP_QSTR_NFC2), MP_ROM_PTR(&pin_P0_10) }, | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_P0_02) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_P0_03) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_P0_04) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_P0_05) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_P0_06) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_P0_07) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P8), MP_ROM_PTR(&pin_P0_08) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P9), MP_ROM_PTR(&pin_P0_09) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P10), MP_ROM_PTR(&pin_P0_10) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P18), MP_ROM_PTR(&pin_P0_18) }, // !Reset button. | ||
| { MP_ROM_QSTR(MP_QSTR_P19), MP_ROM_PTR(&pin_P0_19) }, | ||
| { MP_ROM_QSTR(MP_QSTR_P22), MP_ROM_PTR(&pin_P0_22) }, // green led, low is on. | ||
| { MP_ROM_QSTR(MP_QSTR_P23), MP_ROM_PTR(&pin_P0_23) }, // red led, low is on. | ||
| { MP_ROM_QSTR(MP_QSTR_P24), MP_ROM_PTR(&pin_P0_24) }, // blue led, low is on. | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P0_23) }, // Low is on. | ||
| { MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_P0_22) }, // Low is on. | ||
| { MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_24) }, // Low is on. | ||
|
|
||
| // BUT this is the RESET pin so we can't really use it. | ||
| { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_P0_18) }, // Low is pressed. | ||
| }; | ||
|
|
||
| MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # SparkFun Pro nRF52840 Mini Breakout | ||
|
|
||
| The [SparkFun Pro nRF52840 Mini](https://www.sparkfun.com/products/15025) small breakout board for Raytac's MDBT50Q-P1M module, which features an nRF52840. It breaks out as many pins as it can in an Arduino Pro Mini footprint. Also included on the board are a qwiic (I<sup>2</sup>C) connector, LiPo battery charger, and on/off switch. | ||
|
|
||
| Note: the SparkFun Pro nRF52840 Mini Breakout does not include a QSPI external flash. Any Python code will need to be stored on the internal flash filesystem. | ||
|
|
||
| ## CircuitPython Pin Defs | ||
|
|
||
| CircuitPython pin definitions try to follow those of the [Arduino Pro Mini](https://www.sparkfun.com/products/11113), which the footprint is based on. | ||
|
|
||
| This can be somewhat confusing, especially around the analog pins. Here's a quick pin-map: | ||
|
|
||
| <table> | ||
| <tr><th>Board pin label</th><th>Digital Pin Reference</th><th>Additional Pin Capabilities</th><th>Pin/Port Reference</th></tr> | ||
| <tr><td>17</td><td>D1</td><td>TX</td><td>P0_17</td></tr> | ||
| <tr><td>15</td><td>D0</td><td>RX</td><td>P0_15</td></tr> | ||
| <tr><td>8</td><td></td><td>SDA</td><td>P0_08</td></tr> | ||
| <tr><td>11</td><td></td><td>SCL</td><td>P0_11</td></tr> | ||
| <tr><td>19</td><td>D3</td><td></td><td>P0_19</td></tr> | ||
| <tr><td>20</td><td>D4</td><td></td><td>P0_20</td></tr> | ||
| <tr><td>21</td><td>D5</td><td></td><td>P0_21</td></tr> | ||
| <tr><td>22</td><td>D6</td><td></td><td>P0_22</td></tr> | ||
| <tr><td>23</td><td>D7</td><td></td><td>P0_23</td></tr> | ||
| <tr><td>9</td><td>D8</td><td></td><td>P0_09</td></tr> | ||
| <tr><td>10</td><td>D9</td><td></td><td>P0_10</td></tr> | ||
| <tr><td>2</td><td>D10</td><td>A0</td><td>P0_02</td></tr> | ||
| <tr><td>3</td><td>D11</td><td>MOSI, A1</td><td>P0_03</td></tr> | ||
| <tr><td>31</td><td>D12</td><td>MISO, A7</td><td>P0_31</td></tr> | ||
| <tr><td>30</td><td>D13</td><td>SCK, A6</td><td>P0_31</td></tr> | ||
| <tr><td>29</td><td></td><td>A5</td><td>P0_29</td></tr> | ||
| <tr><td>28</td><td></td><td>A4</td><td>P0_28</td></tr> | ||
| <tr><td>5</td><td></td><td>A3</td><td>P0_05</td></tr> | ||
| <tr><td>4</td><td></td><td>A2</td><td>P0_04</td></tr> | ||
| </table> | ||
|
|
||
| If a pin isn't defined as D0, D1, etc., standard port/pin references should work -- e.g. `P0_17` is pin 17, `P0_02` is pin 2, etc. | ||
|
|
||
| ## Bootloader Notes | ||
|
|
||
| The nRF52840 Mini ships with a slightly modified (i.e pin defs and USB defs) version of the Adafruit nRF52 bootloader, which supports UF2 and CDC bootloading. | ||
|
|
||
| ## Hardware Reference | ||
|
|
||
| The nRF52840 Mini hardware layout is open source: | ||
|
|
||
| * [Schematic](https://cdn.sparkfun.com/assets/learn_tutorials/8/2/0/nrf52840-breakout-mdbt50q-v10.pdf) | ||
| * [Eagle Files](https://cdn.sparkfun.com/assets/learn_tutorials/8/2/0/nrf52840-breakout-mdbt50q-v10.zip) | ||
| * [Hookup Guide](https://learn.sparkfun.com/tutorials/sparkfun-pro-nrf52840-mini-hookup-guide) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2016 Glenn Ruben Bakke | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include "nrfx/hal/nrf_gpio.h" | ||
|
|
||
| #define MICROPY_HW_BOARD_NAME "SparkFun Pro nRF52840 Mini" | ||
| #define MICROPY_HW_MCU_NAME "nRF52840" | ||
| #define MICROPY_PY_SYS_PLATFORM "SFE_NRF52840_Mini" | ||
|
|
||
| #define PORT_HEAP_SIZE (128 * 1024) | ||
| #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 | ||
|
|
||
| #define DEFAULT_I2C_BUS_SCL (&pin_P0_11) | ||
| #define DEFAULT_I2C_BUS_SDA (&pin_P0_08) | ||
|
|
||
| #define DEFAULT_SPI_BUS_SCK (&pin_P0_30) | ||
| #define DEFAULT_SPI_BUS_MOSI (&pin_P0_03) | ||
| #define DEFAULT_SPI_BUS_MISO (&pin_P0_31) | ||
|
|
||
| #define DEFAULT_UART_BUS_RX (&pin_P0_15) | ||
| #define DEFAULT_UART_BUS_TX (&pin_P0_17) | ||
|
|
||
| /* Note: Flash chip is not provided on SparkFun nRF52840 Mini. | ||
| * Leaving this as a reminder for future/similar versions of the board. */ | ||
| // Flash operation mode is determined by MICROPY_QSPI_DATAn pin configuration. | ||
| // A pin config is valid if it is defined and its value is not 0xFF. | ||
| // Quad mode: If all DATA0 --> DATA3 are valid | ||
| // Dual mode: If DATA0 and DATA1 are valid while either DATA2 and/or DATA3 are invalid | ||
| // Single mode: If only DATA0 is valid | ||
| /*#ifdef QSPI_FLASH_FILESYSTEM | ||
| #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) | ||
| #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 21) | ||
| #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 22) | ||
| #define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 23) | ||
| #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19) | ||
| #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 17) | ||
| #endif | ||
| #ifdef SPI_FLASH_FILESYSTEM | ||
| #define SPI_FLASH_MOSI_PIN &pin_P0_20 | ||
| #define SPI_FLASH_MISO_PIN &pin_P0_21 | ||
| #define SPI_FLASH_SCK_PIN &pin_P0_19 | ||
| #define SPI_FLASH_CS_PIN &pin_P0_17 | ||
| #endif*/ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| USB_VID = 0x1B4F | ||
| USB_PID = 0x5289 | ||
| USB_PRODUCT = "SFE_nRF52840_Mini" | ||
| USB_MANUFACTURER = "SparkFun Electronics" | ||
|
|
||
| MCU_SERIES = m4 | ||
| MCU_VARIANT = nrf52 | ||
| MCU_SUB_VARIANT = nrf52840 | ||
| MCU_CHIP = nrf52840 | ||
| SD ?= s140 | ||
| SOFTDEV_VERSION ?= 6.1.0 | ||
|
|
||
| BOOT_SETTING_ADDR = 0xFF000 | ||
|
|
||
| ifeq ($(SD),) | ||
| LD_FILE = boards/nrf52840_1M_256k.ld | ||
| else | ||
| LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld | ||
| endif | ||
|
|
||
| NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 | ||
|
|
||
| QSPI_FLASH_FILESYSTEM = 0 | ||
| EXTERNAL_FLASH_DEVICE_COUNT = 0 | ||
| EXTERNAL_FLASH_DEVICES = |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #include "shared-bindings/board/__init__.h" | ||
|
|
||
| #include "supervisor/shared/board_busses.h" | ||
|
|
||
| STATIC const mp_rom_map_elem_t board_module_globals_table[] = { | ||
| { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P1_15) }, // D1/TX | ||
| { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P0_17) }, // D0/RX | ||
| // D2 on qwiic gap | ||
| { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_P0_19) }, // D3 | ||
| { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_P0_20) }, // D4 | ||
| { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P0_21) }, // D5 | ||
| { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P0_22) }, // D6 | ||
| { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P0_23) }, // D7 | ||
| { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_P0_09) }, // D8 | ||
| { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P0_10) }, // D9 | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P0_02) }, // D10 | ||
| { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_03) }, // D11 | ||
| { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_31) }, // D12 | ||
| { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P0_30) }, // D13 | ||
| { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_P0_29) }, // D14 | ||
| { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_P0_28) }, // D15 | ||
| { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_P0_05) }, // D16 | ||
| { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_P0_04) }, // D17 | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_02) }, // A0 | ||
| { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_03) }, // A1 | ||
| { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_04) }, // A2 | ||
| { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_05) }, // A3 | ||
| { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_28) }, // A4 | ||
| { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_29) }, // A5 | ||
| { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_P0_30) }, // A6 | ||
| { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_P0_31) }, // A7 | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_08) }, // 8 - SDA | ||
| { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_11) }, // 11 - SCL | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_31) }, // 31 - MISO | ||
| { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_03) }, // 3 - MOSI | ||
| { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_30) }, // 30 - SCK | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_07) }, // 7 - Blue LED | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_13) }, // 13 - Button | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_15) }, // 15 - UART RX | ||
| { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_17) }, // 17 - UART TX | ||
|
|
||
| { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, | ||
| { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, | ||
| { MP_ROM_QSTR(MP_QSTR_QWIIC), MP_ROM_PTR(&board_i2c_obj) }, | ||
| { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, | ||
| }; | ||
|
|
||
| MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2018 Dan Halbert for Adafruit Industries | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include <string.h> | ||
|
|
||
| #include "ble.h" | ||
| #include "ble_drv.h" | ||
| #include "ble_hci.h" | ||
| #include "nrf_soc.h" | ||
| #include "py/runtime.h" | ||
|
|
||
| #include "common-hal/bleio/Broadcaster.h" | ||
| #include "shared-bindings/bleio/Adapter.h" | ||
| #include "shared-bindings/bleio/Broadcaster.h" | ||
|
|
||
| static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; | ||
|
|
||
| void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval) { | ||
| common_hal_bleio_adapter_set_enabled(true); // TODO -- Do this somewhere else maybe bleio __init__ | ||
| const mp_float_t min = BLE_GAP_ADV_INTERVAL_MIN * ADV_INTERVAL_UNIT_FLOAT_SECS; | ||
| const mp_float_t max = BLE_GAP_ADV_INTERVAL_MAX * ADV_INTERVAL_UNIT_FLOAT_SECS; | ||
|
|
||
| if (interval < min || interval > max) { | ||
| // Would like to print range using the constants above, but vargs would convert to double. | ||
| mp_raise_ValueError(translate("interval not in range 0.0020 to 10.24")); | ||
| } | ||
| self->interval = interval; | ||
| } | ||
|
|
||
|
|
||
| void common_hal_bleio_broadcaster_start_advertising(bleio_broadcaster_obj_t *self, mp_buffer_info_t *data) { | ||
| uint32_t err_code; | ||
|
|
||
| if (data->len >= BLE_GAP_ADV_SET_DATA_SIZE_MAX) { | ||
| mp_raise_ValueError(translate("Data too large for advertisement packet")); | ||
| } | ||
| memcpy(self->adv_data, data->buf, data->len); | ||
|
|
||
| ble_gap_adv_params_t m_adv_params = { | ||
| .interval = (uint32_t) (self->interval / ADV_INTERVAL_UNIT_FLOAT_SECS), | ||
| .properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED, | ||
| .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, | ||
| .filter_policy = BLE_GAP_ADV_FP_ANY, | ||
| .primary_phy = BLE_GAP_PHY_1MBPS, | ||
| }; | ||
|
|
||
| common_hal_bleio_broadcaster_stop_advertising(self); | ||
|
|
||
| const ble_gap_adv_data_t ble_gap_adv_data = { | ||
| .adv_data.p_data = self->adv_data, | ||
| .adv_data.len = data->len, | ||
| }; | ||
|
|
||
| err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); | ||
| if (err_code == NRF_SUCCESS) { | ||
| err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); | ||
| } | ||
|
|
||
| if (err_code != NRF_SUCCESS) { | ||
| mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); | ||
| } | ||
| } | ||
|
|
||
| void common_hal_bleio_broadcaster_stop_advertising(bleio_broadcaster_obj_t *self) { | ||
|
|
||
| if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) { | ||
| return; | ||
| } | ||
|
|
||
| const uint32_t err_code = sd_ble_gap_adv_stop(m_adv_handle); | ||
|
|
||
| if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { | ||
| mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2018 Artur Pacholec | ||
| * Copyright (c) 2018 Dan Halbert for Adafruit Industries | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H | ||
| #define MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H | ||
|
|
||
| #include "ble.h" | ||
|
|
||
| #include "shared-module/bleio/__init__.h" | ||
| #include "shared-module/bleio/Address.h" | ||
|
|
||
| typedef struct { | ||
| mp_obj_base_t base; | ||
| // In seconds. | ||
| mp_float_t interval; | ||
| // The advertising data buffer is held by us, not by the SD, so we must | ||
| // maintain it and not change it. If we need to change its contents during advertising, | ||
| // there are tricks to get the SD to notice (see DevZone - TBS). | ||
| uint8_t adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; | ||
|
|
||
| } bleio_broadcaster_obj_t; | ||
|
|
||
| #endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2018 Artur Pacholec | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H | ||
| #define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H | ||
|
|
||
| #include "shared-module/bleio/Characteristic.h" | ||
| #include "shared-module/bleio/Service.h" | ||
| #include "common-hal/bleio/UUID.h" | ||
|
|
||
| typedef struct { | ||
| mp_obj_base_t base; | ||
| bleio_service_obj_t *service; | ||
| bleio_uuid_obj_t *uuid; | ||
| mp_obj_t value_data; | ||
| uint16_t handle; | ||
| bleio_characteristic_properties_t props; | ||
| uint16_t user_desc_handle; | ||
| uint16_t cccd_handle; | ||
| uint16_t sccd_handle; | ||
| } bleio_characteristic_obj_t; | ||
|
|
||
| #endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2019 Dan Halbert for Adafruit Industries | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include <string.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "ble_drv.h" | ||
| #include "ble_gatts.h" | ||
| #include "sd_mutex.h" | ||
|
|
||
| #include "lib/utils/interrupt_char.h" | ||
| #include "py/runtime.h" | ||
| #include "py/stream.h" | ||
|
|
||
| #include "tick.h" | ||
|
|
||
| #include "common-hal/bleio/__init__.h" | ||
| #include "common-hal/bleio/CharacteristicBuffer.h" | ||
|
|
||
| STATIC void characteristic_buffer_on_ble_evt(ble_evt_t *ble_evt, void *param) { | ||
| bleio_characteristic_buffer_obj_t *self = (bleio_characteristic_buffer_obj_t *) param; | ||
| switch (ble_evt->header.evt_id) { | ||
| case BLE_GATTS_EVT_WRITE: { | ||
| ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write; | ||
| // Event handle must match the handle for my characteristic. | ||
| if (evt_write->handle == self->characteristic->handle) { | ||
| // Push all the data onto the ring buffer, but wait for any reads to finish. | ||
| sd_mutex_acquire_wait_no_vm(&self->ringbuf_mutex); | ||
| for (size_t i = 0; i < evt_write->len; i++) { | ||
| ringbuf_put(&self->ringbuf, evt_write->data[i]); | ||
| } | ||
| // Don't check for errors: we're in an event handler. | ||
| sd_mutex_release(&self->ringbuf_mutex); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Assumes that timeout and buffer_size have been validated before call. | ||
| void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffer_obj_t *self, | ||
| bleio_characteristic_obj_t *characteristic, | ||
| mp_float_t timeout, | ||
| size_t buffer_size) { | ||
|
|
||
| self->characteristic = characteristic; | ||
| self->timeout_ms = timeout * 1000; | ||
| // This is a macro. | ||
| // true means long-lived, so it won't be moved. | ||
| ringbuf_alloc(&self->ringbuf, buffer_size, true); | ||
| sd_mutex_new(&self->ringbuf_mutex); | ||
|
|
||
| ble_drv_add_event_handler(characteristic_buffer_on_ble_evt, self); | ||
|
|
||
| } | ||
|
|
||
| int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_t *self, uint8_t *data, size_t len, int *errcode) { | ||
| uint64_t start_ticks = ticks_ms; | ||
|
|
||
| // Wait for all bytes received or timeout | ||
| while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) { | ||
| #ifdef MICROPY_VM_HOOK_LOOP | ||
| MICROPY_VM_HOOK_LOOP ; | ||
| // Allow user to break out of a timeout with a KeyboardInterrupt. | ||
| if ( mp_hal_is_interrupted() ) { | ||
| return 0; | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| // Copy received data. Lock out writes while copying. | ||
| sd_mutex_acquire_wait(&self->ringbuf_mutex); | ||
|
|
||
| size_t rx_bytes = MIN(ringbuf_count(&self->ringbuf), len); | ||
| for ( size_t i = 0; i < rx_bytes; i++ ) { | ||
| data[i] = ringbuf_get(&self->ringbuf); | ||
| } | ||
|
|
||
| // Writes now OK. | ||
| sd_mutex_release_check(&self->ringbuf_mutex); | ||
|
|
||
| return rx_bytes; | ||
| } | ||
|
|
||
| uint32_t common_hal_bleio_characteristic_buffer_rx_characters_available(bleio_characteristic_buffer_obj_t *self) { | ||
| return ringbuf_count(&self->ringbuf); | ||
| } | ||
|
|
||
| void common_hal_bleio_characteristic_buffer_clear_rx_buffer(bleio_characteristic_buffer_obj_t *self) { | ||
| // prevent conflict with uart irq | ||
| sd_mutex_acquire_wait(&self->ringbuf_mutex); | ||
| ringbuf_clear(&self->ringbuf); | ||
| sd_mutex_release_check(&self->ringbuf_mutex); | ||
| } | ||
|
|
||
| bool common_hal_bleio_characteristic_buffer_deinited(bleio_characteristic_buffer_obj_t *self) { | ||
| return self->characteristic == NULL; | ||
| } | ||
|
|
||
| void common_hal_bleio_characteristic_buffer_deinit(bleio_characteristic_buffer_obj_t *self) { | ||
| if (!common_hal_bleio_characteristic_buffer_deinited(self)) { | ||
| ble_drv_remove_event_handler(characteristic_buffer_on_ble_evt, self); | ||
| } | ||
| } | ||
|
|
||
| bool common_hal_bleio_characteristic_buffer_connected(bleio_characteristic_buffer_obj_t *self) { | ||
| return self->characteristic != NULL && | ||
| self->characteristic->service != NULL && | ||
| self->characteristic->service->device != NULL && | ||
| common_hal_bleio_device_get_conn_handle(self->characteristic->service->device) != BLE_CONN_HANDLE_INVALID; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * This file is part of the MicroPython project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2018 Artur Pacholec | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H | ||
| #define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H | ||
|
|
||
| #include "nrf_soc.h" | ||
|
|
||
| #include "py/ringbuf.h" | ||
| #include "shared-bindings/bleio/Characteristic.h" | ||
|
|
||
| typedef struct { | ||
| mp_obj_base_t base; | ||
| bleio_characteristic_obj_t *characteristic; | ||
| uint32_t timeout_ms; | ||
| // Ring buffer storing consecutive incoming values. | ||
| ringbuf_t ringbuf; | ||
| nrf_mutex_t ringbuf_mutex; | ||
| } bleio_characteristic_buffer_obj_t; | ||
|
|
||
| #endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H |