Merge remote-tracking branch 'adafruit/master' into hallowing
This commit is contained in:
commit
c2e49dc87f
2
conf.py
2
conf.py
@ -115,9 +115,9 @@ exclude_patterns = ["**/build*",
|
||||
"ports/minimal",
|
||||
"ports/nrf/device",
|
||||
"ports/nrf/drivers",
|
||||
"ports/nrf/hal",
|
||||
"ports/nrf/modules",
|
||||
"ports/nrf/nrfx",
|
||||
"ports/nrf/peripherals",
|
||||
"ports/nrf/usb",
|
||||
"ports/pic16bit",
|
||||
"ports/qemu-arm",
|
||||
|
2249
locale/de_DE.po
Normal file
2249
locale/de_DE.po
Normal file
File diff suppressed because it is too large
Load Diff
2
main.c
2
main.c
@ -451,7 +451,7 @@ void NORETURN __fatal_error(const char *msg) {
|
||||
|
||||
#ifndef NDEBUG
|
||||
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
|
||||
printf("Assertion '%s' failed, at file %s:%d\n", expr, file, line);
|
||||
mp_printf(&mp_plat_print, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);
|
||||
__fatal_error("Assertion failed");
|
||||
}
|
||||
#endif
|
||||
|
@ -48,8 +48,8 @@ bool board_requests_safe_mode(void) {
|
||||
gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN);
|
||||
bool safe_mode = gpio_get_pin_level(PIN_PA14) &&
|
||||
gpio_get_pin_level(PIN_PA28);
|
||||
reset_pin(PIN_PA14);
|
||||
reset_pin(PIN_PA28);
|
||||
reset_pin_number(PIN_PA14);
|
||||
reset_pin_number(PIN_PA28);
|
||||
return safe_mode;
|
||||
}
|
||||
|
||||
|
@ -48,8 +48,8 @@ bool board_requests_safe_mode(void) {
|
||||
gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN);
|
||||
bool safe_mode = gpio_get_pin_level(PIN_PA14) &&
|
||||
gpio_get_pin_level(PIN_PA28);
|
||||
reset_pin(PIN_PA14);
|
||||
reset_pin(PIN_PA28);
|
||||
reset_pin_number(PIN_PA14);
|
||||
reset_pin_number(PIN_PA28);
|
||||
return safe_mode;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
|
||||
|
@ -80,7 +80,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
if (common_hal_analogio_analogin_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
reset_pin(self->pin->number);
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
return;
|
||||
}
|
||||
dac_sync_disable_channel(&self->descriptor, self->channel);
|
||||
reset_pin(PIN_PA02);
|
||||
reset_pin_number(PIN_PA02);
|
||||
// Only deinit the DAC on the SAMD51 if both outputs are free.
|
||||
#ifdef SAMD51
|
||||
if (common_hal_mcu_pin_is_free(&pin_PA02) && common_hal_mcu_pin_is_free(&pin_PA05)) {
|
||||
|
@ -212,11 +212,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
|
||||
return;
|
||||
}
|
||||
|
||||
reset_pin(self->bit_clock->number);
|
||||
reset_pin_number(self->bit_clock->number);
|
||||
self->bit_clock = mp_const_none;
|
||||
reset_pin(self->word_select->number);
|
||||
reset_pin_number(self->word_select->number);
|
||||
self->word_select = mp_const_none;
|
||||
reset_pin(self->data->number);
|
||||
reset_pin_number(self->data->number);
|
||||
self->data = mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -235,8 +235,8 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
|
||||
disconnect_gclk_from_peripheral(self->gclk, I2S_GCLK_ID_0 + self->clock_unit);
|
||||
disable_clock_generator(self->gclk);
|
||||
|
||||
reset_pin(self->clock_pin->number);
|
||||
reset_pin(self->data_pin->number);
|
||||
reset_pin_number(self->clock_pin->number);
|
||||
reset_pin_number(self->data_pin->number);
|
||||
self->clock_pin = mp_const_none;
|
||||
self->data_pin = mp_const_none;
|
||||
}
|
||||
|
@ -248,10 +248,10 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
|
||||
|
||||
tc_set_enable(tc_insts[self->tc_index], false);
|
||||
|
||||
reset_pin(self->left_channel->number);
|
||||
reset_pin_number(self->left_channel->number);
|
||||
self->left_channel = mp_const_none;
|
||||
#ifdef SAMD51
|
||||
reset_pin(self->right_channel->number);
|
||||
reset_pin_number(self->right_channel->number);
|
||||
self->right_channel = mp_const_none;
|
||||
#endif
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
common_hal_mcu_delay_us(3);
|
||||
|
||||
if (!gpio_get_pin_level(sda->number) || !gpio_get_pin_level(scl->number)) {
|
||||
reset_pin(sda->number);
|
||||
reset_pin(scl->number);
|
||||
reset_pin_number(sda->number);
|
||||
reset_pin_number(scl->number);
|
||||
mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
|
||||
}
|
||||
gpio_set_pin_function(sda->number, sda_pinmux);
|
||||
@ -107,8 +107,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
samd_peripherals_sercom_clock_init(sercom, sercom_index);
|
||||
|
||||
if (i2c_m_sync_init(&self->i2c_desc, sercom) != ERR_NONE) {
|
||||
reset_pin(sda->number);
|
||||
reset_pin(scl->number);
|
||||
reset_pin_number(sda->number);
|
||||
reset_pin_number(scl->number);
|
||||
mp_raise_OSError(MP_EIO);
|
||||
}
|
||||
|
||||
@ -116,8 +116,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
||||
|
||||
// Frequency must be set before the I2C device is enabled.
|
||||
if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
|
||||
reset_pin(sda->number);
|
||||
reset_pin(scl->number);
|
||||
reset_pin_number(sda->number);
|
||||
reset_pin_number(scl->number);
|
||||
mp_raise_ValueError(translate("Unsupported baudrate"));
|
||||
}
|
||||
|
||||
@ -144,8 +144,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
|
||||
i2c_m_sync_disable(&self->i2c_desc);
|
||||
i2c_m_sync_deinit(&self->i2c_desc);
|
||||
|
||||
reset_pin(self->sda_pin);
|
||||
reset_pin(self->scl_pin);
|
||||
reset_pin_number(self->sda_pin);
|
||||
reset_pin_number(self->scl_pin);
|
||||
self->sda_pin = NO_PIN;
|
||||
self->scl_pin = NO_PIN;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
struct i2c_m_sync_desc i2c_desc;
|
||||
volatile bool has_lock;
|
||||
bool has_lock;
|
||||
uint8_t scl_pin;
|
||||
uint8_t sda_pin;
|
||||
} busio_i2c_obj_t;
|
||||
|
@ -196,9 +196,9 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
|
||||
}
|
||||
spi_m_sync_disable(&self->spi_desc);
|
||||
spi_m_sync_deinit(&self->spi_desc);
|
||||
reset_pin(self->clock_pin);
|
||||
reset_pin(self->MOSI_pin);
|
||||
reset_pin(self->MISO_pin);
|
||||
reset_pin_number(self->clock_pin);
|
||||
reset_pin_number(self->MOSI_pin);
|
||||
reset_pin_number(self->MISO_pin);
|
||||
self->clock_pin = NO_PIN;
|
||||
}
|
||||
|
||||
|
@ -222,8 +222,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
|
||||
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
|
||||
usart_async_disable(usart_desc_p);
|
||||
usart_async_deinit(usart_desc_p);
|
||||
reset_pin(self->rx_pin);
|
||||
reset_pin(self->tx_pin);
|
||||
reset_pin_number(self->rx_pin);
|
||||
reset_pin_number(self->tx_pin);
|
||||
self->rx_pin = NO_PIN;
|
||||
self->tx_pin = NO_PIN;
|
||||
}
|
||||
@ -249,7 +249,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
|
||||
uint64_t start_ticks = ticks_ms;
|
||||
|
||||
// Busy-wait until timeout or until we've read enough chars.
|
||||
while (ticks_ms - start_ticks < self->timeout_ms) {
|
||||
while (ticks_ms - start_ticks <= self->timeout_ms) {
|
||||
// Read as many chars as we can right now, up to len.
|
||||
size_t num_read = io_read(io, data, len);
|
||||
|
||||
@ -268,6 +268,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
|
||||
#ifdef MICROPY_VM_HOOK_LOOP
|
||||
MICROPY_VM_HOOK_LOOP
|
||||
#endif
|
||||
// If we are zero timeout, make sure we don't loop again (in the event
|
||||
// we read in under 1ms)
|
||||
if (self->timeout_ms == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (total_read == 0) {
|
||||
|
@ -40,6 +40,8 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
||||
digitalio_digitalinout_obj_t* self, const mcu_pin_obj_t* pin) {
|
||||
claim_pin(pin);
|
||||
self->pin = pin;
|
||||
self->output = false;
|
||||
self->open_drain = false;
|
||||
|
||||
// Must set pull after setting direction.
|
||||
gpio_set_pin_direction(pin->number, GPIO_DIRECTION_IN);
|
||||
@ -55,7 +57,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self
|
||||
if (common_hal_digitalio_digitalinout_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
reset_pin(self->pin->number);
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,8 @@ void common_hal_i2cslave_i2c_slave_deinit(i2cslave_i2c_slave_obj_t *self) {
|
||||
|
||||
self->sercom->I2CS.CTRLA.bit.ENABLE = 0;
|
||||
|
||||
reset_pin(self->sda_pin);
|
||||
reset_pin(self->scl_pin);
|
||||
reset_pin_number(self->sda_pin);
|
||||
reset_pin_number(self->scl_pin);
|
||||
self->sda_pin = NO_PIN;
|
||||
self->scl_pin = NO_PIN;
|
||||
}
|
||||
|
@ -91,23 +91,23 @@ void reset_all_pins(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void reset_pin(uint8_t pin) {
|
||||
if (pin >= PORT_BITS) {
|
||||
void reset_pin_number(uint8_t pin_number) {
|
||||
if (pin_number >= PORT_BITS) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
if (pin == MICROPY_HW_NEOPIXEL->number) {
|
||||
if (pin_number == MICROPY_HW_NEOPIXEL->number) {
|
||||
neopixel_in_use = false;
|
||||
rgb_led_status_init();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
if (pin == MICROPY_HW_APA102_MOSI->number ||
|
||||
pin == MICROPY_HW_APA102_SCK->number) {
|
||||
apa102_mosi_in_use = apa102_mosi_in_use && pin != MICROPY_HW_APA102_MOSI->number;
|
||||
apa102_sck_in_use = apa102_sck_in_use && pin != MICROPY_HW_APA102_SCK->number;
|
||||
if (pin_number == MICROPY_HW_APA102_MOSI->number ||
|
||||
pin_number == MICROPY_HW_APA102_SCK->number) {
|
||||
apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number;
|
||||
apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number;
|
||||
if (!apa102_sck_in_use && !apa102_mosi_in_use) {
|
||||
rgb_led_status_init();
|
||||
}
|
||||
@ -115,24 +115,24 @@ void reset_pin(uint8_t pin) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pin == PIN_PA30
|
||||
if (pin_number == PIN_PA30
|
||||
#ifdef SAMD51
|
||||
) {
|
||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_H);
|
||||
gpio_set_pin_function(pin_number, GPIO_PIN_FUNCTION_H);
|
||||
#endif
|
||||
#ifdef SAMD21
|
||||
|| pin == PIN_PA31) {
|
||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_G);
|
||||
|| pin_number == PIN_PA31) {
|
||||
gpio_set_pin_function(pin_number, GPIO_PIN_FUNCTION_G);
|
||||
#endif
|
||||
} else {
|
||||
gpio_set_pin_direction(pin, GPIO_DIRECTION_OFF);
|
||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(pin_number, GPIO_DIRECTION_OFF);
|
||||
gpio_set_pin_function(pin_number, GPIO_PIN_FUNCTION_OFF);
|
||||
}
|
||||
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
if (pin == SPEAKER_ENABLE_PIN->number) {
|
||||
if (pin_number == SPEAKER_ENABLE_PIN->number) {
|
||||
speaker_enable_in_use = false;
|
||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_function(pin_number, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_direction(SPEAKER_ENABLE_PIN->number, GPIO_DIRECTION_OUT);
|
||||
gpio_set_pin_level(SPEAKER_ENABLE_PIN->number, false);
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ extern bool apa102_mosi_in_use;
|
||||
#endif
|
||||
|
||||
void reset_all_pins(void);
|
||||
// reset_pin takes the pin number instead of the pointer so that objects don't
|
||||
// reset_pin_number takes the pin number instead of the pointer so that objects don't
|
||||
// need to store a full pointer.
|
||||
void reset_pin(uint8_t pin);
|
||||
void reset_pin_number(uint8_t pin_number);
|
||||
void claim_pin(const mcu_pin_obj_t* pin);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H
|
||||
|
@ -285,7 +285,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
||||
}
|
||||
}
|
||||
}
|
||||
reset_pin(self->pin->number);
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
|
||||
|
||||
turn_on_cpu_interrupt(self->channel);
|
||||
|
||||
claim_pin(pin);
|
||||
|
||||
// Set config will enable the EIC.
|
||||
pulsein_set_config(self, true);
|
||||
}
|
||||
@ -152,7 +154,7 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
|
||||
return;
|
||||
}
|
||||
turn_off_eic_channel(self->channel);
|
||||
reset_pin(self->pin);
|
||||
reset_pin_number(self->pin);
|
||||
self->pin = NO_PIN;
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,9 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
|
||||
((uint8_t) gpio_get_pin_level(self->pin_a) << 1) |
|
||||
(uint8_t) gpio_get_pin_level(self->pin_b);
|
||||
|
||||
claim_pin(pin_a);
|
||||
claim_pin(pin_b);
|
||||
|
||||
turn_on_eic_channel(self->eic_channel_a, EIC_CONFIG_SENSE0_BOTH_Val, EIC_HANDLER_INCREMENTAL_ENCODER);
|
||||
turn_on_eic_channel(self->eic_channel_b, EIC_CONFIG_SENSE0_BOTH_Val, EIC_HANDLER_INCREMENTAL_ENCODER);
|
||||
}
|
||||
@ -87,9 +90,9 @@ void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_o
|
||||
}
|
||||
turn_off_eic_channel(self->eic_channel_a);
|
||||
turn_off_eic_channel(self->eic_channel_b);
|
||||
reset_pin(self->pin_a);
|
||||
reset_pin_number(self->pin_a);
|
||||
self->pin_a = NO_PIN;
|
||||
reset_pin(self->pin_b);
|
||||
reset_pin_number(self->pin_b);
|
||||
self->pin_b = NO_PIN;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
|
||||
}
|
||||
// We leave the clocks running because they may be in use by others.
|
||||
|
||||
reset_pin(self->config.pin);
|
||||
reset_pin_number(self->config.pin);
|
||||
self->config.pin = NO_PIN;
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 156279784cb3d22f7f8a8d93b4bb55e2d912a5f8
|
||||
Subproject commit b099a172dfb6345a8dac30633df4f6267489c38e
|
@ -24,9 +24,6 @@ ifneq ($(SD), )
|
||||
include drivers/bluetooth/bluetooth_common.mk
|
||||
endif
|
||||
|
||||
# qstr definitions (must come before including py.mk)
|
||||
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
|
||||
|
||||
FROZEN_MPY_DIR = freeze
|
||||
|
||||
# include py core make definitions
|
||||
@ -53,6 +50,7 @@ INC += -I./nrfx/drivers/include
|
||||
INC += -I../../lib/mp-readline
|
||||
INC += -I./drivers/bluetooth
|
||||
INC += -I./drivers
|
||||
INC += -I./peripherals
|
||||
INC += -I../../lib/tinyusb/src
|
||||
INC += -I./usb
|
||||
|
||||
@ -97,28 +95,30 @@ SRC_NRFX = $(addprefix nrfx/,\
|
||||
)
|
||||
|
||||
SRC_C += \
|
||||
mphalport.c \
|
||||
fatfs_port.c \
|
||||
tick.c \
|
||||
background.c \
|
||||
fatfs_port.c \
|
||||
internal_flash.c \
|
||||
mphalport.c \
|
||||
tick.c \
|
||||
boards/$(BOARD)/board.c \
|
||||
boards/$(BOARD)/pins.c \
|
||||
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
|
||||
drivers/bluetooth/ble_drv.c \
|
||||
drivers/bluetooth/ble_uart.c \
|
||||
boards/$(BOARD)/board.c \
|
||||
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
|
||||
nrfx/hal/nrf_nvmc.c \
|
||||
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
|
||||
lib/libc/string0.c \
|
||||
lib/mp-readline/readline.c \
|
||||
lib/oofatfs/ff.c \
|
||||
lib/oofatfs/option/ccsbcs.c \
|
||||
lib/timeutils/timeutils.c \
|
||||
lib/utils/buffer_helper.c \
|
||||
lib/utils/context_manager_helpers.c \
|
||||
lib/utils/pyexec.c \
|
||||
lib/utils/interrupt_char.c \
|
||||
lib/utils/pyexec.c \
|
||||
lib/utils/stdout_helpers.c \
|
||||
lib/utils/sys_stdio_mphal.c \
|
||||
lib/libc/string0.c \
|
||||
lib/mp-readline/readline.c \
|
||||
nrfx/hal/nrf_nvmc.c \
|
||||
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
|
||||
peripherals/nrf/$(MCU_CHIP)/pins.c \
|
||||
supervisor/shared/memory.c
|
||||
|
||||
DRIVERS_SRC_C += $(addprefix modules/,\
|
||||
@ -135,28 +135,29 @@ DRIVERS_SRC_C += $(addprefix modules/,\
|
||||
)
|
||||
|
||||
SRC_COMMON_HAL += \
|
||||
board/__init__.c \
|
||||
digitalio/__init__.c \
|
||||
digitalio/DigitalInOut.c \
|
||||
microcontroller/__init__.c \
|
||||
microcontroller/Pin.c \
|
||||
microcontroller/Processor.c \
|
||||
os/__init__.c \
|
||||
time/__init__.c \
|
||||
analogio/__init__.c \
|
||||
analogio/AnalogIn.c \
|
||||
analogio/AnalogOut.c \
|
||||
busio/__init__.c\
|
||||
analogio/__init__.c \
|
||||
board/__init__.c \
|
||||
busio/I2C.c \
|
||||
busio/SPI.c \
|
||||
busio/UART.c \
|
||||
pulseio/__init__.c \
|
||||
busio/__init__.c\
|
||||
digitalio/DigitalInOut.c \
|
||||
digitalio/__init__.c \
|
||||
microcontroller/Pin.c \
|
||||
microcontroller/Processor.c \
|
||||
microcontroller/__init__.c \
|
||||
neopixel_write/__init__.c \
|
||||
os/__init__.c \
|
||||
pulseio/PWMOut.c \
|
||||
pulseio/PulseIn.c \
|
||||
pulseio/PulseOut.c \
|
||||
pulseio/PWMOut.c \
|
||||
pulseio/__init__.c \
|
||||
storage/__init__.c \
|
||||
supervisor/__init__.c \
|
||||
supervisor/Runtime.c \
|
||||
supervisor/__init__.c \
|
||||
time/__init__.c \
|
||||
|
||||
ifneq ($(SD), )
|
||||
SRC_COMMON_HAL += \
|
||||
@ -238,7 +239,6 @@ FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
|
||||
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
|
||||
|
||||
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
OBJ += $(BUILD)/pins_gen.o
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_NRFX:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
|
||||
@ -350,29 +350,8 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(DRIVERS_SRC_C) $(SRC_COMMON_
|
||||
# SRC_QSTR
|
||||
SRC_QSTR_AUTO_DEPS +=
|
||||
|
||||
# Making OBJ use an order-only depenedency on the generated pins.h file
|
||||
# has the side effect of making the pins.h file before we actually compile
|
||||
# any of the objects. The normal dependency generation will deal with the
|
||||
# case when pins.h is modified. But when it doesn't exist, we don't know
|
||||
# which source files might need it.
|
||||
$(OBJ): | $(HEADER_BUILD)/pins.h
|
||||
|
||||
# Use a pattern rule here so that make will only call make-pins.py once to make
|
||||
# both pins_g.c and pins.h
|
||||
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
|
||||
$(ECHO) "Create $@"
|
||||
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC)
|
||||
|
||||
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
|
||||
$(call compile_c)
|
||||
|
||||
MAKE_PINS = boards/make-pins.py
|
||||
BOARD_PINS = boards/$(BOARD)/pins.csv
|
||||
AF_FILE = $(MCU_VARIANT)_af.csv
|
||||
PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
|
||||
GEN_PINS_SRC = $(BUILD)/pins_gen.c
|
||||
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
|
||||
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
|
||||
|
||||
ifneq ($(FROZEN_DIR),)
|
||||
# To use frozen source modules, put your .py files in a subdirectory (eg scripts/)
|
||||
|
114
ports/nrf/board_busses.c
Normal file
114
ports/nrf/board_busses.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft 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 "shared-bindings/busio/I2C.h"
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#include "shared-bindings/busio/UART.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "mpconfigboard.h"
|
||||
#include "nrf/pins.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
|
||||
STATIC mp_obj_t board_i2c(void) {
|
||||
mp_raise_NotImplementedError(translate("No default I2C bus"));
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
STATIC mp_obj_t i2c_singleton = NULL;
|
||||
|
||||
STATIC mp_obj_t board_i2c(void) {
|
||||
|
||||
if (i2c_singleton == NULL) {
|
||||
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
|
||||
self->base.type = &busio_i2c_type;
|
||||
|
||||
assert_pin_free(DEFAULT_I2C_BUS_SDA);
|
||||
assert_pin_free(DEFAULT_I2C_BUS_SCL);
|
||||
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
|
||||
i2c_singleton = (mp_obj_t)self;
|
||||
}
|
||||
return i2c_singleton;
|
||||
|
||||
}
|
||||
#endif
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
|
||||
|
||||
#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
|
||||
STATIC mp_obj_t board_spi(void) {
|
||||
mp_raise_NotImplementedError(translate("No default SPI bus"));
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
STATIC mp_obj_t spi_singleton = NULL;
|
||||
|
||||
STATIC mp_obj_t board_spi(void) {
|
||||
|
||||
if (spi_singleton == NULL) {
|
||||
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
|
||||
self->base.type = &busio_spi_type;
|
||||
assert_pin_free(DEFAULT_SPI_BUS_SCK);
|
||||
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
|
||||
assert_pin_free(DEFAULT_SPI_BUS_MISO);
|
||||
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
|
||||
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
|
||||
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
|
||||
common_hal_busio_spi_construct(self, clock, mosi, miso);
|
||||
spi_singleton = (mp_obj_t)self;
|
||||
}
|
||||
return spi_singleton;
|
||||
}
|
||||
#endif
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
|
||||
|
||||
#if !defined(DEFAULT_UART_BUS_RX) || !defined(DEFAULT_UART_BUS_TX)
|
||||
STATIC mp_obj_t board_uart(void) {
|
||||
mp_raise_NotImplementedError(translate("No default UART bus"));
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
STATIC mp_obj_t uart_singleton = NULL;
|
||||
|
||||
STATIC mp_obj_t board_uart(void) {
|
||||
if (uart_singleton == NULL) {
|
||||
busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
|
||||
self->base.type = &busio_uart_type;
|
||||
|
||||
assert_pin_free(DEFAULT_UART_BUS_RX);
|
||||
assert_pin_free(DEFAULT_UART_BUS_TX);
|
||||
|
||||
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
|
||||
const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
|
||||
|
||||
common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
|
||||
uart_singleton = (mp_obj_t)self;
|
||||
}
|
||||
return uart_singleton;
|
||||
}
|
||||
#endif
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart);
|
39
ports/nrf/board_busses.h
Normal file
39
ports/nrf/board_busses.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft 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_NRF_BOARD_BUSSES_H
|
||||
#define MICROPY_INCLUDED_NRF_BOARD_BUSSES_H
|
||||
|
||||
void board_i2c(void);
|
||||
extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
|
||||
|
||||
void board_spi(void);
|
||||
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
|
||||
|
||||
void board_uart(void);
|
||||
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_BOARD_BUSSES_H
|
@ -52,8 +52,8 @@ bool board_requests_safe_mode(void) {
|
||||
// gpio_set_pin_pull_mode(PIN_PA28, GPIO_PULL_DOWN);
|
||||
// bool safe_mode = gpio_get_pin_level(PIN_PA14) &&
|
||||
// gpio_get_pin_level(PIN_PA28);
|
||||
// reset_pin(PIN_PA14);
|
||||
// reset_pin(PIN_PA28);
|
||||
// reset_pin_number(PIN_PA14);
|
||||
// reset_pin_number(PIN_PA28);
|
||||
// return safe_mode;
|
||||
|
||||
return false;
|
||||
|
@ -34,3 +34,13 @@
|
||||
|
||||
#define PORT_HEAP_SIZE (32 * 1024)
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_P0_26)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_P0_25)
|
||||
|
||||
#define DEFAULT_SPI_BUS_SCK (&pin_P0_12)
|
||||
#define DEFAULT_SPI_BUS_MOSI (&pin_P0_13)
|
||||
#define DEFAULT_SPI_BUS_MISO (&pin_P0_14)
|
||||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_P0_08)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_P0_06)
|
||||
|
@ -1,6 +1,8 @@
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
# Historical: nrf52 means nrf52832
|
||||
MCU_SUB_VARIANT = nrf52
|
||||
MCU_CHIP = nrf52832
|
||||
SD ?= s132
|
||||
SOFTDEV_VERSION ?= 2.0.1
|
||||
|
||||
@ -8,4 +10,4 @@ LD_FILE = boards/feather_nrf52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
|
||||
BOOT_FILE = boards/feather_nrf52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single
|
||||
|
||||
BOOT_SETTING_ADDR = 0x7F000
|
||||
NRF_DEFINES += -DNRF52832_XXAA
|
||||
NRF_DEFINES += -DNRF52832_XXAA -DNRF52832
|
||||
|
46
ports/nrf/boards/feather_nrf52832/pins.c
Normal file
46
ports/nrf/boards/feather_nrf52832/pins.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "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_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_29) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_14) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_06) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_DFU), MP_ROM_PTR(&pin_P0_20) },
|
||||
|
||||
{ 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_D27), MP_ROM_PTR(&pin_P0_27) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_D30), MP_ROM_PTR(&pin_P0_30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_P0_30) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_D31), MP_ROM_PTR(&pin_P0_31) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_P0_31) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P0_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_P0_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_P0_16) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_17) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P0_19) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_25) },
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -1,24 +0,0 @@
|
||||
A0,P0_02
|
||||
A1,P0_03
|
||||
A2,P0_04
|
||||
A3,P0_05
|
||||
TX,P0_06
|
||||
RX,P0_08
|
||||
NFC1,P0_09
|
||||
NFC2,P0_10
|
||||
D11,P0_11
|
||||
SCK,P0_12
|
||||
MOSI,P0_13
|
||||
MISO,P0_14
|
||||
D15,P0_15
|
||||
D16,P0_16
|
||||
LED1,P0_17
|
||||
LED2,P0_19
|
||||
DFU,P0_20
|
||||
SDA,P0_25
|
||||
SCL,P0_26
|
||||
D27,P0_27
|
||||
A4,P0_28
|
||||
A5,P0_29
|
||||
A6,P0_30
|
||||
A7,P0_31
|
|
@ -29,20 +29,16 @@
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "Adafruit Feather nRF52840 Express"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "Feather52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "Feather52840Express"
|
||||
|
||||
// #define MICROPY_HW_NEOPIXEL NRF_GPIO_PIN_MAP(0, 13)
|
||||
#define MICROPY_HW_NEOPIXEL (&pin_P0_13)
|
||||
|
||||
// #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(1, 9)
|
||||
// #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 11)
|
||||
// #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 12)
|
||||
// #define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 14)
|
||||
// #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 8)
|
||||
// #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 8)
|
||||
|
||||
// #define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||
// #define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||
// #define MICROPY_HW_UART_HWFC (0)
|
||||
#define MICROPY_QSPI_DATA0 (&pin_P1_09)
|
||||
#define MICROPY_QSPI_DATA1 (&pin_P0_11)
|
||||
#define MICROPY_QSPI_DATA2 (&pin_P0_12)
|
||||
#define MICROPY_QSPI_DATA3 (&pin_P0_14)
|
||||
#define MICROPY_QSPI_SCK (&pin_P0_08)
|
||||
#define MICROPY_QSPI_CS (&pin_P1_08)
|
||||
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
||||
|
||||
@ -64,12 +60,12 @@
|
||||
|
||||
#define BOARD_HAS_CRYSTAL 1
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL NRF_GPIO_PIN_MAP(1, 11)
|
||||
#define DEFAULT_I2C_BUS_SDA NRF_GPIO_PIN_MAP(1, 12)
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_P1_11)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_P1_12)
|
||||
|
||||
#define DEFAULT_SPI_BUS_SCK NRF_GPIO_PIN_MAP(0, 20)
|
||||
#define DEFAULT_SPI_BUS_MOSI NRF_GPIO_PIN_MAP(0, 23)
|
||||
#define DEFAULT_SPI_BUS_MISO NRF_GPIO_PIN_MAP(0, 22)
|
||||
#define DEFAULT_SPI_BUS_SCK (&pin_P0_20)
|
||||
#define DEFAULT_SPI_BUS_MOSI (&pin_P0_23)
|
||||
#define DEFAULT_SPI_BUS_MISO (&pin_P0_22)
|
||||
|
||||
#define DEFAULT_UART_BUS_RX NRF_GPIO_PIN_MAP(1, 0)
|
||||
#define DEFAULT_UART_BUS_TX NRF_GPIO_PIN_MAP(0, 24)
|
||||
#define DEFAULT_UART_BUS_RX (&pin_P1_0)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_P0_24)
|
||||
|
@ -1,6 +1,7 @@
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
MCU_CHIP = nrf52840
|
||||
SD ?= s140
|
||||
SOFTDEV_VERSION ?= 6.1.0
|
||||
|
||||
@ -12,4 +13,4 @@ else
|
||||
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52840_XXAA
|
||||
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
|
||||
|
41
ports/nrf/boards/feather_nrf52840_express/pins.c
Normal file
41
ports/nrf/boards/feather_nrf52840_express/pins.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "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_30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_31) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_03) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_VDIV), MP_ROM_PTR(&pin_P0_05) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P1_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P1_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P0_27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P0_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_07) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_13) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_23) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_22) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_TXD), MP_ROM_PTR(&pin_P0_24) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_RXD), MP_ROM_PTR(&pin_P1_00) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P1_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P1_12) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_P1_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_P1_10) },
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -1,48 +0,0 @@
|
||||
P0_00,P0_00
|
||||
P0_01,P0_01
|
||||
P0_02,P0_02
|
||||
P0_03,P0_03
|
||||
P0_04,P0_04
|
||||
P0_05,P0_05
|
||||
P0_06,P0_06
|
||||
P0_07,P0_07
|
||||
P0_08,P0_08
|
||||
P0_09,P0_09
|
||||
P0_10,P0_10
|
||||
P0_11,P0_11
|
||||
P0_12,P0_12
|
||||
P0_13,P0_13
|
||||
P0_14,P0_14
|
||||
P0_15,P0_15
|
||||
P0_16,P0_16
|
||||
P0_17,P0_17
|
||||
P0_18,P0_18
|
||||
P0_19,P0_19
|
||||
P0_20,P0_20
|
||||
P0_21,P0_21
|
||||
P0_22,P0_22
|
||||
P0_23,P0_23
|
||||
P0_24,P0_24
|
||||
P0_25,P0_25
|
||||
P0_26,P0_26
|
||||
P0_27,P0_27
|
||||
P0_28,P0_28
|
||||
P0_29,P0_29
|
||||
P0_30,P0_30
|
||||
P0_31,P0_31
|
||||
P1_00,P1_00
|
||||
P1_01,P1_01
|
||||
P1_02,P1_02
|
||||
P1_03,P1_03
|
||||
P1_04,P1_04
|
||||
P1_05,P1_05
|
||||
P1_06,P1_06
|
||||
P1_07,P1_07
|
||||
P1_08,P1_08
|
||||
P1_09,P1_09
|
||||
P1_10,P1_10
|
||||
P1_11,P1_11
|
||||
P1_12,P1_12
|
||||
P1_13,P1_13
|
||||
P1_14,P1_14
|
||||
P1_15,P1_15
|
|
@ -4,6 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Glenn Ruben Bakke
|
||||
* 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
|
||||
|
@ -1,6 +1,8 @@
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
# Historical: nrf52 means nrf52832
|
||||
MCU_SUB_VARIANT = nrf52
|
||||
MCU_CHIP = nrf52832
|
||||
SD ?= s132
|
||||
SOFTDEV_VERSION ?= 5.0.0
|
||||
|
||||
@ -10,4 +12,4 @@ else
|
||||
LD_FILE = boards/nrf52832_512k_64k_s132_$(SOFTDEV_VERSION).ld
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52832_XXAA
|
||||
NRF_DEFINES += -DNRF52832_XXAA -DNRF52832
|
||||
|
40
ports/nrf/boards/pca10040/pins.c
Normal file
40
ports/nrf/boards/pca10040/pins.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "board_busses.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) },
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -1,31 +0,0 @@
|
||||
P0_01,P0_01
|
||||
P0_02,P0_02
|
||||
P0_03,P0_03
|
||||
P0_04,P0_04
|
||||
P0_05,P0_05
|
||||
P0_06,P0_06
|
||||
P0_07,P0_07
|
||||
P0_08,P0_08
|
||||
P0_09,P0_09
|
||||
P0_10,P0_10
|
||||
P0_11,P0_11
|
||||
P0_12,P0_12
|
||||
P0_13,P0_13
|
||||
P0_14,P0_14
|
||||
P0_15,P0_15
|
||||
P0_16,P0_16
|
||||
P0_17,P0_17
|
||||
P0_18,P0_18
|
||||
P0_19,P0_19
|
||||
P0_20,P0_20
|
||||
P0_21,P0_21
|
||||
P0_22,P0_22
|
||||
P0_23,P0_23
|
||||
P0_24,P0_24
|
||||
P0_25,P0_25
|
||||
P0_26,P0_26
|
||||
P0_27,P0_27
|
||||
P0_28,P0_28
|
||||
P0_29,P0_29
|
||||
P0_30,P0_30
|
||||
P0_31,P0_31
|
|
@ -24,10 +24,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "PCA10056"
|
||||
#define MICROPY_HW_BOARD_NAME "PCA10056 nRF52840-DK"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "nRF52840-DK"
|
||||
|
||||
// See legend on bottom of board
|
||||
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8)
|
||||
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6)
|
||||
#define MICROPY_HW_UART_HWFC (0)
|
||||
@ -38,3 +39,12 @@
|
||||
// Temp (could be removed) 0: usb cdc (default), 1 : hwuart (jlink)
|
||||
#define CFG_HWUART_FOR_SERIAL 0
|
||||
|
||||
#define DEFAULT_I2C_BUS_SCL (&pin_P0_27)
|
||||
#define DEFAULT_I2C_BUS_SDA (&pin_P0_26)
|
||||
|
||||
#define DEFAULT_SPI_BUS_SCK (&pin_P1_15)
|
||||
#define DEFAULT_SPI_BUS_MOSI (&pin_P1_13)
|
||||
#define DEFAULT_SPI_BUS_MISO (&pin_P1_14)
|
||||
|
||||
#define DEFAULT_UART_BUS_RX (&pin_P1_01)
|
||||
#define DEFAULT_UART_BUS_TX (&pin_P1_02)
|
||||
|
@ -1,6 +1,7 @@
|
||||
MCU_SERIES = m4
|
||||
MCU_VARIANT = nrf52
|
||||
MCU_SUB_VARIANT = nrf52840
|
||||
MCU_CHIP = nrf52840
|
||||
SD ?= s140
|
||||
SOFTDEV_VERSION ?= 6.1.0
|
||||
|
||||
@ -12,4 +13,4 @@ else
|
||||
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
|
||||
endif
|
||||
|
||||
NRF_DEFINES += -DNRF52840_XXAA
|
||||
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
|
||||
|
129
ports/nrf/boards/pca10056/pins.c
Normal file
129
ports/nrf/boards/pca10056/pins.c
Normal file
@ -0,0 +1,129 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "board_busses.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_03) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_04) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON1), MP_ROM_PTR(&pin_P0_11) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON2), MP_ROM_PTR(&pin_P0_12) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_13) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_P0_14) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_P0_15) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_P0_16) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) },
|
||||
|
||||
// RESET { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON3), MP_ROM_PTR(&pin_P0_24) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_BUTTON4), MP_ROM_PTR(&pin_P0_25) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_26) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_27) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_28) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_29) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_30) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_31) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P1_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P1_01) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P1_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P1_02) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P1_03) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_P1_04) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_P1_05) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P1_06) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_P1_07) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P1_08) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_P1_10) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P1_11) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P1_12) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P1_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P1_13) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P1_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P1_14) },
|
||||
|
||||
// Note that there is no LED on D13.
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P1_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P1_15) },
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -1,48 +0,0 @@
|
||||
P0_00,P0_00
|
||||
P0_01,P0_01
|
||||
P0_02,P0_02
|
||||
P0_03,P0_03
|
||||
P0_04,P0_04
|
||||
P0_05,P0_05
|
||||
P0_06,P0_06
|
||||
P0_07,P0_07
|
||||
P0_08,P0_08
|
||||
P0_09,P0_09
|
||||
P0_10,P0_10
|
||||
P0_11,P0_11
|
||||
P0_12,P0_12
|
||||
P0_13,P0_13
|
||||
P0_14,P0_14
|
||||
P0_15,P0_15
|
||||
P0_16,P0_16
|
||||
P0_17,P0_17
|
||||
P0_18,P0_18
|
||||
P0_19,P0_19
|
||||
P0_20,P0_20
|
||||
P0_21,P0_21
|
||||
P0_22,P0_22
|
||||
P0_23,P0_23
|
||||
P0_24,P0_24
|
||||
P0_25,P0_25
|
||||
P0_26,P0_26
|
||||
P0_27,P0_27
|
||||
P0_28,P0_28
|
||||
P0_29,P0_29
|
||||
P0_30,P0_30
|
||||
P0_31,P0_31
|
||||
P1_00,P1_00
|
||||
P1_01,P1_01
|
||||
P1_02,P1_02
|
||||
P1_03,P1_03
|
||||
P1_04,P1_04
|
||||
P1_05,P1_05
|
||||
P1_06,P1_06
|
||||
P1_07,P1_07
|
||||
P1_08,P1_08
|
||||
P1_09,P1_09
|
||||
P1_10,P1_10
|
||||
P1_11,P1_11
|
||||
P1_12,P1_12
|
||||
P1_13,P1_13
|
||||
P1_14,P1_14
|
||||
P1_15,P1_15
|
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
* Copyright (c) 2017 Scott Shawcroft 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
|
||||
@ -24,20 +24,30 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __MICROPY_INCLUDED_NRF5_PIN_H__
|
||||
#define __MICROPY_INCLUDED_NRF5_PIN_H__
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "boards/board.h"
|
||||
#include "nrfx.h"
|
||||
#include "usb.h"
|
||||
|
||||
void board_init(void) {
|
||||
|
||||
// Clock
|
||||
NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk);
|
||||
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
|
||||
|
||||
usb_init();
|
||||
}
|
||||
|
||||
bool board_requests_safe_mode(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void reset_board(void) {
|
||||
|
||||
}
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
qstr name;
|
||||
|
||||
uint32_t port : 1;
|
||||
uint32_t pin : 5; // Some ARM processors use 32 bits/PORT
|
||||
uint32_t adc_channel : 4; // 0 is no ADC, ADC channel from 1 to 8
|
||||
} pin_obj_t;
|
||||
|
||||
extern const mp_obj_type_t mcu_pin_type;
|
||||
|
||||
#endif // __MICROPY_INCLUDED_NRF5_PIN_H__
|
Binary file not shown.
32
ports/nrf/boards/pca10059/mpconfigboard.h
Normal file
32
ports/nrf/boards/pca10059/mpconfigboard.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define MICROPY_HW_BOARD_NAME "PCA10059 nRF52840 Dongle"
|
||||
#define MICROPY_HW_MCU_NAME "nRF52840"
|
||||
#define MICROPY_PY_SYS_PLATFORM "nRF52840-DK"
|
||||
|
||||
#define PORT_HEAP_SIZE (128 * 1024)
|
||||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
|
17
ports/nrf/boards/pca10059/mpconfigboard.mk
Normal file
17
ports/nrf/boards/pca10059/mpconfigboard.mk
Normal file
@ -0,0 +1,17 @@
|
||||
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
|
42
ports/nrf/boards/pca10059/pins.c
Normal file
42
ports/nrf/boards/pca10059/pins.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
#include "board_busses.h"
|
||||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_06) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED2_R), MP_ROM_PTR(&pin_P0_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED2_G), MP_ROM_PTR(&pin_P1_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_LED2_B), MP_ROM_PTR(&pin_P0_12) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_SW1), MP_ROM_PTR(&pin_P1_06) },
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
|
@ -38,8 +38,9 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
|
||||
if (pin->adc_channel == 0)
|
||||
mp_raise_ValueError(translate("Pin does not have ADC capabilities"));
|
||||
|
||||
nrf_gpio_cfg_default(NRF_GPIO_PIN_MAP(pin->port, pin->pin));
|
||||
nrf_gpio_cfg_default(pin->number);
|
||||
|
||||
claim_pin(pin);
|
||||
self->pin = pin;
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
if (common_hal_analogio_analogin_deinited(self))
|
||||
return;
|
||||
|
||||
nrf_gpio_cfg_default(NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin));
|
||||
nrf_gpio_cfg_default(self->pin->number);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,7 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, uint16_t value) {
|
||||
|
||||
}
|
||||
|
@ -54,15 +54,15 @@ static uint8_t twi_error_to_mp(const nrfx_err_t err) {
|
||||
}
|
||||
|
||||
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) {
|
||||
if (scl->pin == sda->pin)
|
||||
if (scl->number == sda->number)
|
||||
mp_raise_ValueError(translate("Invalid pins"));
|
||||
|
||||
const nrfx_twim_t instance = NRFX_TWIM_INSTANCE(INST_NO);
|
||||
self->twim = instance;
|
||||
|
||||
nrfx_twim_config_t config = NRFX_TWIM_DEFAULT_CONFIG;
|
||||
config.scl = NRF_GPIO_PIN_MAP(scl->port, scl->pin);
|
||||
config.sda = NRF_GPIO_PIN_MAP(sda->port, sda->pin);
|
||||
config.scl = scl->number;
|
||||
config.sda = sda->number;
|
||||
|
||||
// change freq. only if it's less than the default 400K
|
||||
if (frequency < 100000) {
|
||||
@ -71,6 +71,11 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
|
||||
config.frequency = NRF_TWIM_FREQ_250K;
|
||||
}
|
||||
|
||||
self->scl_pin_number = scl->number;
|
||||
self->sda_pin_number = sda->number;
|
||||
claim_pin(sda);
|
||||
claim_pin(scl);
|
||||
|
||||
nrfx_err_t err = nrfx_twim_init(&self->twim, &config, NULL, NULL);
|
||||
|
||||
// A soft reset doesn't uninit the driver so we might end up with a invalid state
|
||||
@ -79,14 +84,15 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *
|
||||
err = nrfx_twim_init(&self->twim, &config, NULL, NULL);
|
||||
}
|
||||
|
||||
if (err != NRFX_SUCCESS)
|
||||
if (err != NRFX_SUCCESS) {
|
||||
common_hal_busio_i2c_deinit(self);
|
||||
mp_raise_OSError(MP_EIO);
|
||||
}
|
||||
|
||||
self->inited = true;
|
||||
}
|
||||
|
||||
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
|
||||
return !self->inited;
|
||||
return self->sda_pin_number == NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
|
||||
@ -95,7 +101,10 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
|
||||
|
||||
nrfx_twim_uninit(&self->twim);
|
||||
|
||||
self->inited = false;
|
||||
reset_pin_number(self->sda_pin_number);
|
||||
reset_pin_number(self->scl_pin_number);
|
||||
self->sda_pin_number = NO_PIN;
|
||||
self->scl_pin_number = NO_PIN;
|
||||
}
|
||||
|
||||
// nrfx_twim_tx doesn't support 0-length data so we fall back to the hal API
|
||||
|
@ -34,8 +34,9 @@
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
nrfx_twim_t twim;
|
||||
bool inited;
|
||||
bool has_lock;
|
||||
uint8_t scl_pin_number;
|
||||
uint8_t sda_pin_number;
|
||||
} busio_i2c_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_I2C_H
|
||||
|
@ -77,13 +77,25 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
|
||||
nrfx_spim_config_t config = NRFX_SPIM_DEFAULT_CONFIG;
|
||||
config.frequency = NRF_SPIM_FREQ_8M;
|
||||
|
||||
config.sck_pin = NRF_GPIO_PIN_MAP(clock->port, clock->pin);
|
||||
config.sck_pin = clock->number;
|
||||
self->clock_pin_number = clock->number;
|
||||
claim_pin(clock);
|
||||
|
||||
if (mosi != (mcu_pin_obj_t*)&mp_const_none_obj)
|
||||
config.mosi_pin = NRF_GPIO_PIN_MAP(mosi->port, mosi->pin);
|
||||
if (mosi != (mcu_pin_obj_t*)&mp_const_none_obj) {
|
||||
config.mosi_pin = mosi->number;
|
||||
self->MOSI_pin_number = mosi->number;
|
||||
claim_pin(mosi);
|
||||
} else {
|
||||
self->MOSI_pin_number = NO_PIN;
|
||||
}
|
||||
|
||||
if (miso != (mcu_pin_obj_t*)&mp_const_none_obj)
|
||||
config.miso_pin = NRF_GPIO_PIN_MAP(miso->port, miso->pin);
|
||||
if (miso != (mcu_pin_obj_t*)&mp_const_none_obj) {
|
||||
config.miso_pin = miso->number;
|
||||
self->MISO_pin_number = mosi->number;
|
||||
claim_pin(miso);
|
||||
} else {
|
||||
self->MISO_pin_number = NO_PIN;
|
||||
}
|
||||
|
||||
nrfx_err_t err = nrfx_spim_init(&self->spim, &config, NULL, NULL);
|
||||
|
||||
@ -93,14 +105,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
|
||||
err = nrfx_spim_init(&self->spim, &config, NULL, NULL);
|
||||
}
|
||||
|
||||
if (err != NRFX_SUCCESS)
|
||||
if (err != NRFX_SUCCESS) {
|
||||
common_hal_busio_spi_deinit(self);
|
||||
mp_raise_OSError(MP_EIO);
|
||||
|
||||
self->inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
|
||||
return !self->inited;
|
||||
return self->clock_pin_number == NO_PIN;
|
||||
}
|
||||
|
||||
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
|
||||
@ -109,7 +121,9 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
|
||||
|
||||
nrfx_spim_uninit(&self->spim);
|
||||
|
||||
self->inited = false;
|
||||
reset_pin_number(self->clock_pin_number);
|
||||
reset_pin_number(self->MOSI_pin_number);
|
||||
reset_pin_number(self->MISO_pin_number);
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
|
||||
|
@ -33,8 +33,10 @@
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
nrfx_spim_t spim;
|
||||
bool inited;
|
||||
bool has_lock;
|
||||
uint8_t clock_pin_number;
|
||||
uint8_t MOSI_pin_number;
|
||||
uint8_t MISO_pin_number;
|
||||
} busio_spi_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_SPI_H
|
||||
|
@ -36,8 +36,6 @@
|
||||
|
||||
#include "tick.h"
|
||||
|
||||
#include "pins.h"
|
||||
|
||||
void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
||||
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
|
||||
uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout,
|
||||
|
@ -32,9 +32,12 @@
|
||||
|
||||
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
||||
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
claim_pin(pin);
|
||||
self->pin = pin;
|
||||
self->output = false;
|
||||
self->open_drain = false;
|
||||
|
||||
nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(pin->port, pin->pin), NRF_GPIO_PIN_NOPULL);
|
||||
nrf_gpio_cfg_input(pin->number, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
return DIGITALINOUT_OK;
|
||||
}
|
||||
@ -47,66 +50,56 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
|
||||
if (common_hal_digitalio_digitalinout_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
nrf_gpio_cfg_default(self->pin->number);
|
||||
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
nrf_gpio_cfg_default(pin);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(
|
||||
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
|
||||
nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
self->output = false;
|
||||
nrf_gpio_cfg_input(self->pin->number, NRF_GPIO_PIN_NOPULL);
|
||||
common_hal_digitalio_digitalinout_set_pull(self, pull);
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_output(
|
||||
digitalio_digitalinout_obj_t *self, bool value,
|
||||
digitalio_drive_mode_t drive_mode) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
|
||||
self->output = true;
|
||||
self->open_drain = (drive_mode == DRIVE_MODE_OPEN_DRAIN);
|
||||
|
||||
nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL);
|
||||
nrf_gpio_cfg_input(self->pin->number, NRF_GPIO_PIN_NOPULL);
|
||||
|
||||
common_hal_digitalio_digitalinout_set_value(self, value);
|
||||
}
|
||||
|
||||
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
|
||||
return (nrf_gpio_pin_dir_get(pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? DIRECTION_OUTPUT : DIRECTION_INPUT;
|
||||
return self->output ? DIRECTION_OUTPUT : DIRECTION_INPUT;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_set_value(
|
||||
digitalio_digitalinout_obj_t *self, bool value) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
|
||||
if (value && self->open_drain) {
|
||||
nrf_gpio_pin_dir_set(pin, NRF_GPIO_PIN_DIR_INPUT);
|
||||
nrf_gpio_pin_dir_set(self->pin->number, NRF_GPIO_PIN_DIR_INPUT);
|
||||
} else {
|
||||
nrf_gpio_pin_dir_set(pin, NRF_GPIO_PIN_DIR_OUTPUT);
|
||||
nrf_gpio_pin_write(pin, value);
|
||||
nrf_gpio_pin_dir_set(self->pin->number, NRF_GPIO_PIN_DIR_OUTPUT);
|
||||
nrf_gpio_pin_write(self->pin->number, value);
|
||||
}
|
||||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_get_value(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
const nrf_gpio_pin_dir_t dir = nrf_gpio_pin_dir_get(pin);
|
||||
|
||||
if (dir == NRF_GPIO_PIN_DIR_INPUT) {
|
||||
if (self->open_drain)
|
||||
if (nrf_gpio_pin_dir_get(self->pin->number) == NRF_GPIO_PIN_DIR_INPUT) {
|
||||
if (self->open_drain) {
|
||||
return true;
|
||||
|
||||
return nrf_gpio_pin_read(pin);
|
||||
}
|
||||
|
||||
return nrf_gpio_pin_out_read(pin);
|
||||
return nrf_gpio_pin_read(self->pin->number);
|
||||
}
|
||||
|
||||
return nrf_gpio_pin_out_read(self->pin->number);
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_set_drive_mode(
|
||||
@ -117,21 +110,22 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
|
||||
|
||||
// True is implemented differently between modes so reset the value to make
|
||||
// sure its correct for the new mode.
|
||||
if (value)
|
||||
if (value) {
|
||||
common_hal_digitalio_digitalinout_set_value(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
if (self->open_drain)
|
||||
if (self->open_drain) {
|
||||
return DRIVE_MODE_OPEN_DRAIN;
|
||||
}
|
||||
|
||||
return DRIVE_MODE_PUSH_PULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_set_pull(
|
||||
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
|
||||
const uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
nrf_gpio_pin_pull_t hal_pull = NRF_GPIO_PIN_NOPULL;
|
||||
|
||||
switch (pull) {
|
||||
@ -146,20 +140,21 @@ void common_hal_digitalio_digitalinout_set_pull(
|
||||
break;
|
||||
}
|
||||
|
||||
nrf_gpio_cfg_input(pin, hal_pull);
|
||||
nrf_gpio_cfg_input(self->pin->number, hal_pull);
|
||||
}
|
||||
|
||||
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
uint32_t pin = NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin);
|
||||
uint32_t pin = self->pin->number;
|
||||
// Changes pin to be a relative pin number in port.
|
||||
NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&pin);
|
||||
|
||||
if (nrf_gpio_pin_dir_get(pin) == NRF_GPIO_PIN_DIR_OUTPUT) {
|
||||
if (nrf_gpio_pin_dir_get(self->pin->number) == NRF_GPIO_PIN_DIR_OUTPUT) {
|
||||
mp_raise_AttributeError(translate("Cannot get pull while in output mode"));
|
||||
return PULL_NONE;
|
||||
}
|
||||
|
||||
switch (reg->PIN_CNF[self->pin->pin] & GPIO_PIN_CNF_PULL_Msk) {
|
||||
switch (reg->PIN_CNF[pin] & GPIO_PIN_CNF_PULL_Msk) {
|
||||
case NRF_GPIO_PIN_PULLUP:
|
||||
return PULL_UP;
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
bool output;
|
||||
bool open_drain;
|
||||
} digitalio_digitalinout_obj_t;
|
||||
|
||||
|
@ -24,16 +24,135 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
||||
return true;
|
||||
}
|
||||
#include "nrf/pins.h"
|
||||
#include "supervisor/shared/rgb_led_status.h"
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
bool neopixel_in_use;
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
bool apa102_sck_in_use;
|
||||
bool apa102_mosi_in_use;
|
||||
#endif
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
bool speaker_enable_in_use;
|
||||
#endif
|
||||
|
||||
// Bit mask of claimed pins on each of up to two ports. nrf52832 has one port; nrf52840 has two.
|
||||
STATIC uint32_t claimed_pins[GPIO_COUNT];
|
||||
|
||||
void reset_all_pins(void) {
|
||||
for (uint32_t pin = 0; pin < NUMBER_OF_PINS; ++pin)
|
||||
for (size_t i = 0; i < GPIO_COUNT; i++) {
|
||||
claimed_pins[i] = 0;
|
||||
}
|
||||
|
||||
for (uint32_t pin = 0; pin < NUMBER_OF_PINS; ++pin) {
|
||||
nrf_gpio_cfg_default(pin);
|
||||
}
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
neopixel_in_use = false;
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
apa102_sck_in_use = false;
|
||||
apa102_mosi_in_use = false;
|
||||
#endif
|
||||
|
||||
// After configuring SWD because it may be shared.
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
speaker_enable_in_use = false;
|
||||
// TODO set pin to out and turn off.
|
||||
#endif
|
||||
}
|
||||
|
||||
// Mark pin as free and return it to a quiescent state.
|
||||
void reset_pin_number(uint8_t pin_number) {
|
||||
if (pin_number == NO_PIN) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear claimed bit.
|
||||
claimed_pins[nrf_pin_port(pin_number)] &= ~(1 << nrf_relative_pin_number(pin_number));
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
if (pin_number == MICROPY_HW_NEOPIXEL->number) {
|
||||
neopixel_in_use = false;
|
||||
rgb_led_status_init();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
if (pin == MICROPY_HW_APA102_MOSI->number ||
|
||||
pin == MICROPY_HW_APA102_SCK->number) {
|
||||
apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number;
|
||||
apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number;
|
||||
if (!apa102_sck_in_use && !apa102_mosi_in_use) {
|
||||
rgb_led_status_init();
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
if (pin_number == SPEAKER_ENABLE_PIN->number) {
|
||||
speaker_enable_in_use = false;
|
||||
common_hal_digitalio_digitalinout_switch_to_output(
|
||||
nrf_gpio_pin_dir_set(pin_number, NRF_GPIO_PIN_DIR_OUTPUT);
|
||||
nrf_gpio_pin_write(pin_number, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void claim_pin(const mcu_pin_obj_t* pin) {
|
||||
// Set bit in claimed_pins bitmask.
|
||||
claimed_pins[nrf_pin_port(pin->number)] |= 1 << nrf_relative_pin_number(pin->number);
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
if (pin == MICROPY_HW_NEOPIXEL) {
|
||||
neopixel_in_use = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
if (pin == MICROPY_HW_APA102_MOSI) {
|
||||
apa102_mosi_in_use = true;
|
||||
}
|
||||
if (pin == MICROPY_HW_APA102_SCK) {
|
||||
apa102_sck_in_use = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
if (pin == SPEAKER_ENABLE_PIN) {
|
||||
speaker_enable_in_use = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
if (pin == MICROPY_HW_NEOPIXEL) {
|
||||
return !neopixel_in_use;
|
||||
}
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
if (pin == MICROPY_HW_APA102_MOSI) {
|
||||
return !apa102_mosi_in_use;
|
||||
}
|
||||
if (pin == MICROPY_HW_APA102_SCK) {
|
||||
return !apa102_sck_in_use;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SPEAKER_ENABLE_PIN
|
||||
if (pin == SPEAKER_ENABLE_PIN) {
|
||||
return !speaker_enable_in_use;
|
||||
}
|
||||
#endif
|
||||
|
||||
return !(claimed_pins[nrf_pin_port(pin->number)] & (1 << nrf_relative_pin_number(pin->number)));
|
||||
}
|
||||
|
@ -27,10 +27,33 @@
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H
|
||||
|
||||
#include "nrf_pin.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
#define mcu_pin_obj_t pin_obj_t
|
||||
#include "peripherals/nrf/pins.h"
|
||||
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
extern bool neopixel_in_use;
|
||||
#endif
|
||||
#ifdef MICROPY_HW_APA102_MOSI
|
||||
extern bool apa102_sck_in_use;
|
||||
extern bool apa102_mosi_in_use;
|
||||
#endif
|
||||
|
||||
void reset_all_pins(void);
|
||||
// reset_pin_number takes the pin number instead of the pointer so that objects don't
|
||||
// need to store a full pointer.
|
||||
void reset_pin_number(uint8_t pin);
|
||||
void claim_pin(const mcu_pin_obj_t* pin);
|
||||
|
||||
// Lower 5 bits of a pin number are the pin number in a port.
|
||||
// upper bits (just one bit for current chips) is port number.
|
||||
|
||||
static inline uint8_t nrf_pin_port(uint8_t absolute_pin) {
|
||||
return absolute_pin >> 5;
|
||||
}
|
||||
|
||||
static inline uint8_t nrf_relative_pin_number(uint8_t absolute_pin) {
|
||||
return absolute_pin & 0x1f;
|
||||
}
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H
|
||||
|
@ -62,3 +62,58 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = {
|
||||
.type = &mcu_processor_type,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) },
|
||||
#ifdef NRF52840
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) },
|
||||
#endif
|
||||
};
|
||||
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_globals_table);
|
||||
|
265
ports/nrf/common-hal/neopixel_write/__init__.c
Normal file
265
ports/nrf/common-hal/neopixel_write/__init__.c
Normal file
@ -0,0 +1,265 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 hathach 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 "py/mphal.h"
|
||||
#include "shared-bindings/neopixel_write/__init__.h"
|
||||
#include "nrf_pwm.h"
|
||||
|
||||
// https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp
|
||||
// [[[Begin of the Neopixel NRF52 EasyDMA implementation
|
||||
// by the Hackerspace San Salvador]]]
|
||||
// This technique uses the PWM peripheral on the NRF52. The PWM uses the
|
||||
// EasyDMA feature included on the chip. This technique loads the duty
|
||||
// cycle configuration for each cycle when the PWM is enabled. For this
|
||||
// to work we need to store a 16 bit configuration for each bit of the
|
||||
// RGB(W) values in the pixel buffer.
|
||||
// Comparator values for the PWM were hand picked and are guaranteed to
|
||||
// be 100% organic to preserve freshness and high accuracy. Current
|
||||
// parameters are:
|
||||
// * PWM Clock: 16Mhz
|
||||
// * Minimum step time: 62.5ns
|
||||
// * Time for zero in high (T0H): 0.31ms
|
||||
// * Time for one in high (T1H): 0.75ms
|
||||
// * Cycle time: 1.25us
|
||||
// * Frequency: 800Khz
|
||||
// For 400Khz we just double the calculated times.
|
||||
// ---------- BEGIN Constants for the EasyDMA implementation -----------
|
||||
// The PWM starts the duty cycle in LOW. To start with HIGH we
|
||||
// need to set the 15th bit on each register.
|
||||
|
||||
// WS2812 (rev A) timing is 0.35 and 0.7us
|
||||
//#define MAGIC_T0H 5UL | (0x8000) // 0.3125us
|
||||
//#define MAGIC_T1H 12UL | (0x8000) // 0.75us
|
||||
|
||||
// WS2812B (rev B) timing is 0.4 and 0.8 us
|
||||
#define MAGIC_T0H 6UL | (0x8000) // 0.375us
|
||||
#define MAGIC_T1H 13UL | (0x8000) // 0.8125us
|
||||
#define CTOPVAL 20UL // 1.25us
|
||||
|
||||
// ---------- END Constants for the EasyDMA implementation -------------
|
||||
//
|
||||
// If there is no device available an alternative cycle-counter
|
||||
// implementation is tried.
|
||||
// The nRF52832 runs with a fixed clock of 64Mhz. The alternative
|
||||
// implementation is the same as the one used for the Teensy 3.0/1/2 but
|
||||
// with the Nordic SDK HAL & registers syntax.
|
||||
// The number of cycles was hand picked and is guaranteed to be 100%
|
||||
// organic to preserve freshness and high accuracy.
|
||||
// ---------- BEGIN Constants for cycle counter implementation ---------
|
||||
#define CYCLES_800_T0H 18 // ~0.36 uS
|
||||
#define CYCLES_800_T1H 41 // ~0.76 uS
|
||||
#define CYCLES_800 71 // ~1.25 uS
|
||||
|
||||
// ---------- END of Constants for cycle counter implementation --------
|
||||
|
||||
// find a free PWM device, which is not enabled and has no connected pins
|
||||
static NRF_PWM_Type* find_free_pwm (void) {
|
||||
NRF_PWM_Type* PWM[] = {
|
||||
NRF_PWM0, NRF_PWM1, NRF_PWM2
|
||||
#ifdef NRF_PWM3
|
||||
, NRF_PWM3
|
||||
#endif
|
||||
};
|
||||
|
||||
for ( int device = 0; device < ARRAY_SIZE(PWM); device++ ) {
|
||||
if ( (PWM[device]->ENABLE == 0) &&
|
||||
(PWM[device]->PSEL.OUT[0] & PWM_PSEL_OUT_CONNECT_Msk) && (PWM[device]->PSEL.OUT[1] & PWM_PSEL_OUT_CONNECT_Msk) &&
|
||||
(PWM[device]->PSEL.OUT[2] & PWM_PSEL_OUT_CONNECT_Msk) && (PWM[device]->PSEL.OUT[3] & PWM_PSEL_OUT_CONNECT_Msk) ) {
|
||||
return PWM[device];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) {
|
||||
// To support both the SoftDevice + Neopixels we use the EasyDMA
|
||||
// feature from the NRF25. However this technique implies to
|
||||
// generate a pattern and store it on the memory. The actual
|
||||
// memory used in bytes corresponds to the following formula:
|
||||
// totalMem = numBytes*8*2+(2*2)
|
||||
// The two additional bytes at the end are needed to reset the
|
||||
// sequence.
|
||||
//
|
||||
// If there is not enough memory, we will fall back to cycle counter
|
||||
// using DWT
|
||||
uint32_t pattern_size = numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t);
|
||||
uint16_t* pixels_pattern = NULL;
|
||||
|
||||
NRF_PWM_Type* pwm = find_free_pwm();
|
||||
|
||||
// only malloc if there is PWM device available
|
||||
if ( pwm != NULL ) {
|
||||
pixels_pattern = (uint16_t *) m_malloc(pattern_size, false);
|
||||
}
|
||||
|
||||
// Use the identified device to choose the implementation
|
||||
// If a PWM device is available use DMA
|
||||
if ( (pixels_pattern != NULL) && (pwm != NULL) ) {
|
||||
uint16_t pos = 0; // bit position
|
||||
|
||||
for ( uint16_t n = 0; n < numBytes; n++ ) {
|
||||
uint8_t pix = pixels[n];
|
||||
|
||||
for ( uint8_t mask = 0x80, i = 0; mask > 0; mask >>= 1, i++ ) {
|
||||
pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
// Zero padding to indicate the end of sequence
|
||||
pixels_pattern[++pos] = 0 | (0x8000); // Seq end
|
||||
pixels_pattern[++pos] = 0 | (0x8000); // Seq end
|
||||
|
||||
// Set the wave mode to count UP
|
||||
// Set the PWM to use the 16MHz clock
|
||||
// Setting of the maximum count
|
||||
// but keeping it on 16Mhz allows for more granularity just
|
||||
// in case someone wants to do more fine-tuning of the timing.
|
||||
nrf_pwm_configure(pwm, NRF_PWM_CLK_16MHz, NRF_PWM_MODE_UP, CTOPVAL);
|
||||
|
||||
// Disable loops, we want the sequence to repeat only once
|
||||
nrf_pwm_loop_set(pwm, 0);
|
||||
|
||||
// On the "Common" setting the PWM uses the same pattern for the
|
||||
// for supported sequences. The pattern is stored on half-word of 16bits
|
||||
nrf_pwm_decoder_set(pwm, PWM_DECODER_LOAD_Common, PWM_DECODER_MODE_RefreshCount);
|
||||
|
||||
// Pointer to the memory storing the pattern
|
||||
nrf_pwm_seq_ptr_set(pwm, 0, pixels_pattern);
|
||||
|
||||
// Calculation of the number of steps loaded from memory.
|
||||
nrf_pwm_seq_cnt_set(pwm, 0, pattern_size / sizeof(uint16_t));
|
||||
|
||||
// The following settings are ignored with the current config.
|
||||
nrf_pwm_seq_refresh_set(pwm, 0, 0);
|
||||
nrf_pwm_seq_end_delay_set(pwm, 0, 0);
|
||||
|
||||
// The Neopixel implementation is a blocking algorithm. DMA
|
||||
// allows for non-blocking operation. To "simulate" a blocking
|
||||
// operation we enable the interruption for the end of sequence
|
||||
// and block the execution thread until the event flag is set by
|
||||
// the peripheral.
|
||||
// pwm->INTEN |= (PWM_INTEN_SEQEND0_Enabled<<PWM_INTEN_SEQEND0_Pos);
|
||||
|
||||
// PSEL must be configured before enabling PWM
|
||||
nrf_pwm_pins_set(pwm, (uint32_t[]) {digitalinout->pin->number, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL} );
|
||||
|
||||
// Enable the PWM
|
||||
nrf_pwm_enable(pwm);
|
||||
|
||||
// After all of this and many hours of reading the documentation
|
||||
// we are ready to start the sequence...
|
||||
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
|
||||
nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0);
|
||||
|
||||
// But we have to wait for the flag to be set.
|
||||
while ( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {
|
||||
#ifdef MICROPY_VM_HOOK_LOOP
|
||||
MICROPY_VM_HOOK_LOOP
|
||||
#endif
|
||||
}
|
||||
|
||||
// Before leave we clear the flag for the event.
|
||||
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
|
||||
|
||||
// We need to disable the device and disconnect
|
||||
// all the outputs before leave or the device will not
|
||||
// be selected on the next call.
|
||||
// TODO: Check if disabling the device causes performance issues.
|
||||
nrf_pwm_disable(pwm);
|
||||
nrf_pwm_pins_set(pwm, (uint32_t[]) {0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL, 0xFFFFFFFFUL} );
|
||||
|
||||
m_free(pixels_pattern);
|
||||
} // End of DMA implementation
|
||||
// ---------------------------------------------------------------------
|
||||
else {
|
||||
// Fall back to DWT
|
||||
// If you are using the Bluetooth SoftDevice we advise you to not disable
|
||||
// the interrupts. Disabling the interrupts even for short periods of time
|
||||
// causes the SoftDevice to stop working.
|
||||
// Disable the interrupts only in cases where you need high performance for
|
||||
// the LEDs and if you are not using the EasyDMA feature.
|
||||
__disable_irq();
|
||||
|
||||
uint32_t decoded_pin = digitalinout->pin->number;
|
||||
NRF_GPIO_Type* port = nrf_gpio_pin_port_decode(&decoded_pin);
|
||||
|
||||
uint32_t pinMask = ( 1UL << decoded_pin );
|
||||
|
||||
uint32_t CYCLES_X00 = CYCLES_800;
|
||||
uint32_t CYCLES_X00_T1H = CYCLES_800_T1H;
|
||||
uint32_t CYCLES_X00_T0H = CYCLES_800_T0H;
|
||||
|
||||
// Enable DWT in debug core
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
|
||||
// Tries to re-send the frame if is interrupted by the SoftDevice.
|
||||
while ( 1 ) {
|
||||
uint8_t *p = pixels;
|
||||
|
||||
uint32_t cycStart = DWT->CYCCNT;
|
||||
uint32_t cyc = 0;
|
||||
|
||||
for ( uint16_t n = 0; n < numBytes; n++ ) {
|
||||
uint8_t pix = *p++;
|
||||
|
||||
for ( uint8_t mask = 0x80; mask; mask >>= 1 ) {
|
||||
while ( DWT->CYCCNT - cyc < CYCLES_X00 )
|
||||
;
|
||||
cyc = DWT->CYCCNT;
|
||||
|
||||
port->OUTSET |= pinMask;
|
||||
|
||||
if ( pix & mask ) {
|
||||
while ( DWT->CYCCNT - cyc < CYCLES_X00_T1H )
|
||||
;
|
||||
} else {
|
||||
while ( DWT->CYCCNT - cyc < CYCLES_X00_T0H )
|
||||
;
|
||||
}
|
||||
|
||||
port->OUTCLR |= pinMask;
|
||||
}
|
||||
}
|
||||
while ( DWT->CYCCNT - cyc < CYCLES_X00 )
|
||||
;
|
||||
|
||||
// If total time longer than 25%, resend the whole data.
|
||||
// Since we are likely to be interrupted by SoftDevice
|
||||
if ( (DWT->CYCCNT - cycStart) < (8 * numBytes * ((CYCLES_X00 * 5) / 4)) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
// re-send need 300us delay
|
||||
mp_hal_delay_us(300);
|
||||
}
|
||||
|
||||
// Enable interrupts again
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
@ -146,7 +146,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
||||
// check if mapped to PWM channel already
|
||||
for(int i=0; i<PWM_MAX_MODULE; i++)
|
||||
{
|
||||
int ch = pin2channel(pwm_arr[i], NRF_GPIO_PIN_MAP(pin->port, pin->pin));
|
||||
int ch = pin2channel(pwm_arr[i], pin->number);
|
||||
if ( ch >= 0 )
|
||||
{
|
||||
self->pwm = pwm_arr[i];
|
||||
@ -163,12 +163,12 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
||||
|
||||
if (self->pwm)
|
||||
{
|
||||
nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(pin->port, pin->pin));
|
||||
nrf_gpio_cfg_output(pin->number);
|
||||
|
||||
// disable before mapping pin channel
|
||||
self->pwm->ENABLE = 0;
|
||||
|
||||
self->pwm->PSEL.OUT[self->channel] = NRF_GPIO_PIN_MAP(pin->port, pin->pin);
|
||||
self->pwm->PSEL.OUT[self->channel] = pin->number;
|
||||
|
||||
self->pwm->COUNTERTOP = (PWM_MAX_FREQ/frequency);
|
||||
self->freq = frequency;
|
||||
@ -203,7 +203,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
||||
}
|
||||
}
|
||||
|
||||
nrf_gpio_cfg_default(NRF_GPIO_PIN_MAP(self->pin->port, self->pin->pin));
|
||||
nrf_gpio_cfg_default(self->pin->number);
|
||||
|
||||
self->pwm = NULL;
|
||||
self->pin = mp_const_none;
|
||||
|
@ -180,6 +180,7 @@ extern const struct _mp_obj_module_t struct_module;
|
||||
extern const struct _mp_obj_module_t time_module;
|
||||
extern const struct _mp_obj_module_t supervisor_module;
|
||||
extern const struct _mp_obj_module_t gamepad_module;
|
||||
extern const struct _mp_obj_module_t neopixel_write_module;
|
||||
extern const struct _mp_obj_module_t usb_hid_module;
|
||||
extern const struct _mp_obj_module_t bleio_module;
|
||||
|
||||
@ -210,6 +211,7 @@ extern const struct _mp_obj_module_t mp_module_ubluepy;
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_digitalio ), (mp_obj_t)&digitalio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_pulseio ), (mp_obj_t)&pulseio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_microcontroller ), (mp_obj_t)µcontroller_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_neopixel_write ), (mp_obj_t)&neopixel_write_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_bitbangio ), (mp_obj_t)&bitbangio_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_os ), (mp_obj_t)&os_module }, \
|
||||
{ MP_OBJ_NEW_QSTR (MP_QSTR_random ), (mp_obj_t)&random_module }, \
|
||||
|
@ -1,48 +0,0 @@
|
||||
P0_00
|
||||
P0_01
|
||||
P0_02,AIN0
|
||||
P0_03,AIN1
|
||||
P0_04,AIN2
|
||||
P0_05,AIN3
|
||||
P0_06
|
||||
P0_07
|
||||
P0_08
|
||||
P0_09
|
||||
P0_10
|
||||
P0_11
|
||||
P0_12
|
||||
P0_13
|
||||
P0_14
|
||||
P0_15
|
||||
P0_16
|
||||
P0_17
|
||||
P0_18
|
||||
P0_19
|
||||
P0_20
|
||||
P0_21
|
||||
P0_22
|
||||
P0_23
|
||||
P0_24
|
||||
P0_25
|
||||
P0_26
|
||||
P0_27
|
||||
P0_28,AIN4
|
||||
P0_29,AIN5
|
||||
P0_30,AIN6
|
||||
P0_31,AIN7
|
||||
P1_00
|
||||
P1_01
|
||||
P1_02
|
||||
P1_03
|
||||
P1_04
|
||||
P1_05
|
||||
P1_06
|
||||
P1_07
|
||||
P1_08
|
||||
P1_09
|
||||
P1_10
|
||||
P1_11
|
||||
P1_12
|
||||
P1_13
|
||||
P1_14
|
||||
P1_15
|
|
@ -34,4 +34,15 @@
|
||||
#define NRFX_UART_DEFAULT_CONFIG_PARITY NRF_UART_PARITY_EXCLUDED
|
||||
#define NRFX_UART_DEFAULT_CONFIG_BAUDRATE NRF_UART_BAUDRATE_115200
|
||||
|
||||
// PWM
|
||||
#define NRFX_PWM0_ENABLED 1
|
||||
#define NRFX_PWM1_ENABLED 1
|
||||
#define NRFX_PWM2_ENABLED 1
|
||||
|
||||
#ifdef NRF_PWM3
|
||||
#define NRFX_PWM3_ENABLED 1
|
||||
#else
|
||||
#define NRFX_PWM3_ENABLED 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
65
ports/nrf/peripherals/nrf/nrf52832/pins.c
Normal file
65
ports/nrf/peripherals/nrf/nrf52832/pins.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// DO NOT include this file directly. Use shared-bindings/microcontroller/Pin.h instead to ensure
|
||||
// that all necessary includes are already included.
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/mphal.h"
|
||||
#include "nrf/pins.h"
|
||||
|
||||
const mcu_pin_obj_t pin_P0_00 = PIN(P0_00, 0, 0, 0);
|
||||
const mcu_pin_obj_t pin_P0_01 = PIN(P0_01, 0, 1, 0);
|
||||
const mcu_pin_obj_t pin_P0_02 = PIN(P0_02, 0, 2, SAADC_CH_PSELP_PSELP_AnalogInput0);
|
||||
const mcu_pin_obj_t pin_P0_03 = PIN(P0_03, 0, 3, SAADC_CH_PSELP_PSELP_AnalogInput1);
|
||||
const mcu_pin_obj_t pin_P0_04 = PIN(P0_04, 0, 4, SAADC_CH_PSELP_PSELP_AnalogInput2);
|
||||
const mcu_pin_obj_t pin_P0_05 = PIN(P0_05, 0, 5, SAADC_CH_PSELP_PSELP_AnalogInput3);
|
||||
const mcu_pin_obj_t pin_P0_06 = PIN(P0_06, 0, 6, 0);
|
||||
const mcu_pin_obj_t pin_P0_07 = PIN(P0_07, 0, 7, 0);
|
||||
const mcu_pin_obj_t pin_P0_08 = PIN(P0_08, 0, 8, 0);
|
||||
const mcu_pin_obj_t pin_P0_09 = PIN(P0_09, 0, 9, 0);
|
||||
const mcu_pin_obj_t pin_P0_10 = PIN(P0_10, 0, 10, 0);
|
||||
const mcu_pin_obj_t pin_P0_11 = PIN(P0_11, 0, 11, 0);
|
||||
const mcu_pin_obj_t pin_P0_12 = PIN(P0_12, 0, 12, 0);
|
||||
const mcu_pin_obj_t pin_P0_13 = PIN(P0_13, 0, 13, 0);
|
||||
const mcu_pin_obj_t pin_P0_14 = PIN(P0_14, 0, 14, 0);
|
||||
const mcu_pin_obj_t pin_P0_15 = PIN(P0_15, 0, 15, 0);
|
||||
const mcu_pin_obj_t pin_P0_16 = PIN(P0_16, 0, 16, 0);
|
||||
const mcu_pin_obj_t pin_P0_17 = PIN(P0_17, 0, 17, 0);
|
||||
const mcu_pin_obj_t pin_P0_18 = PIN(P0_18, 0, 18, 0);
|
||||
const mcu_pin_obj_t pin_P0_19 = PIN(P0_19, 0, 19, 0);
|
||||
const mcu_pin_obj_t pin_P0_20 = PIN(P0_20, 0, 20, 0);
|
||||
const mcu_pin_obj_t pin_P0_21 = PIN(P0_21, 0, 21, 0);
|
||||
const mcu_pin_obj_t pin_P0_22 = PIN(P0_22, 0, 22, 0);
|
||||
const mcu_pin_obj_t pin_P0_23 = PIN(P0_23, 0, 23, 0);
|
||||
const mcu_pin_obj_t pin_P0_24 = PIN(P0_24, 0, 24, 0);
|
||||
const mcu_pin_obj_t pin_P0_25 = PIN(P0_25, 0, 25, 0);
|
||||
const mcu_pin_obj_t pin_P0_26 = PIN(P0_26, 0, 26, 0);
|
||||
const mcu_pin_obj_t pin_P0_27 = PIN(P0_27, 0, 27, 0);
|
||||
const mcu_pin_obj_t pin_P0_28 = PIN(P0_28, 0, 28, SAADC_CH_PSELP_PSELP_AnalogInput4);
|
||||
const mcu_pin_obj_t pin_P0_29 = PIN(P0_29, 0, 29, SAADC_CH_PSELP_PSELP_AnalogInput5);
|
||||
const mcu_pin_obj_t pin_P0_30 = PIN(P0_30, 0, 30, SAADC_CH_PSELP_PSELP_AnalogInput6);
|
||||
const mcu_pin_obj_t pin_P0_31 = PIN(P0_31, 0, 31, SAADC_CH_PSELP_PSELP_AnalogInput7);
|
63
ports/nrf/peripherals/nrf/nrf52832/pins.h
Normal file
63
ports/nrf/peripherals/nrf/nrf52832/pins.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by 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_NRF_PERIPHERALS_NRF52832_PINS_H
|
||||
#define MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52832_PINS_H
|
||||
|
||||
extern const mcu_pin_obj_t pin_P0_00;
|
||||
extern const mcu_pin_obj_t pin_P0_01;
|
||||
extern const mcu_pin_obj_t pin_P0_02;
|
||||
extern const mcu_pin_obj_t pin_P0_03;
|
||||
extern const mcu_pin_obj_t pin_P0_04;
|
||||
extern const mcu_pin_obj_t pin_P0_05;
|
||||
extern const mcu_pin_obj_t pin_P0_06;
|
||||
extern const mcu_pin_obj_t pin_P0_07;
|
||||
extern const mcu_pin_obj_t pin_P0_08;
|
||||
extern const mcu_pin_obj_t pin_P0_09;
|
||||
extern const mcu_pin_obj_t pin_P0_10;
|
||||
extern const mcu_pin_obj_t pin_P0_11;
|
||||
extern const mcu_pin_obj_t pin_P0_12;
|
||||
extern const mcu_pin_obj_t pin_P0_13;
|
||||
extern const mcu_pin_obj_t pin_P0_14;
|
||||
extern const mcu_pin_obj_t pin_P0_15;
|
||||
extern const mcu_pin_obj_t pin_P0_16;
|
||||
extern const mcu_pin_obj_t pin_P0_17;
|
||||
extern const mcu_pin_obj_t pin_P0_18;
|
||||
extern const mcu_pin_obj_t pin_P0_19;
|
||||
extern const mcu_pin_obj_t pin_P0_20;
|
||||
extern const mcu_pin_obj_t pin_P0_21;
|
||||
extern const mcu_pin_obj_t pin_P0_22;
|
||||
extern const mcu_pin_obj_t pin_P0_23;
|
||||
extern const mcu_pin_obj_t pin_P0_24;
|
||||
extern const mcu_pin_obj_t pin_P0_25;
|
||||
extern const mcu_pin_obj_t pin_P0_26;
|
||||
extern const mcu_pin_obj_t pin_P0_27;
|
||||
extern const mcu_pin_obj_t pin_P0_28;
|
||||
extern const mcu_pin_obj_t pin_P0_29;
|
||||
extern const mcu_pin_obj_t pin_P0_30;
|
||||
extern const mcu_pin_obj_t pin_P0_31;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52832_PINS_H
|
78
ports/nrf/peripherals/nrf/nrf52840/pins.c
Normal file
78
ports/nrf/peripherals/nrf/nrf52840/pins.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "py/obj.h"
|
||||
#include "py/mphal.h"
|
||||
#include "nrf/pins.h"
|
||||
|
||||
const mcu_pin_obj_t pin_P0_00 = PIN(P0_00, 0, 0, 0);
|
||||
const mcu_pin_obj_t pin_P0_01 = PIN(P0_01, 0, 1, 0);
|
||||
const mcu_pin_obj_t pin_P0_02 = PIN(P0_02, 0, 2, SAADC_CH_PSELP_PSELP_AnalogInput0);
|
||||
const mcu_pin_obj_t pin_P0_03 = PIN(P0_03, 0, 3, SAADC_CH_PSELP_PSELP_AnalogInput1);
|
||||
const mcu_pin_obj_t pin_P0_04 = PIN(P0_04, 0, 4, SAADC_CH_PSELP_PSELP_AnalogInput2);
|
||||
const mcu_pin_obj_t pin_P0_05 = PIN(P0_05, 0, 5, SAADC_CH_PSELP_PSELP_AnalogInput3);
|
||||
const mcu_pin_obj_t pin_P0_06 = PIN(P0_06, 0, 6, 0);
|
||||
const mcu_pin_obj_t pin_P0_07 = PIN(P0_07, 0, 7, 0);
|
||||
const mcu_pin_obj_t pin_P0_08 = PIN(P0_08, 0, 8, 0);
|
||||
const mcu_pin_obj_t pin_P0_09 = PIN(P0_09, 0, 9, 0);
|
||||
const mcu_pin_obj_t pin_P0_10 = PIN(P0_10, 0, 10, 0);
|
||||
const mcu_pin_obj_t pin_P0_11 = PIN(P0_11, 0, 11, 0);
|
||||
const mcu_pin_obj_t pin_P0_12 = PIN(P0_12, 0, 12, 0);
|
||||
const mcu_pin_obj_t pin_P0_13 = PIN(P0_13, 0, 13, 0);
|
||||
const mcu_pin_obj_t pin_P0_14 = PIN(P0_14, 0, 14, 0);
|
||||
const mcu_pin_obj_t pin_P0_15 = PIN(P0_15, 0, 15, 0);
|
||||
const mcu_pin_obj_t pin_P0_16 = PIN(P0_16, 0, 16, 0);
|
||||
const mcu_pin_obj_t pin_P0_17 = PIN(P0_17, 0, 17, 0);
|
||||
const mcu_pin_obj_t pin_P0_18 = PIN(P0_18, 0, 18, 0);
|
||||
const mcu_pin_obj_t pin_P0_19 = PIN(P0_19, 0, 19, 0);
|
||||
const mcu_pin_obj_t pin_P0_20 = PIN(P0_20, 0, 20, 0);
|
||||
const mcu_pin_obj_t pin_P0_21 = PIN(P0_21, 0, 21, 0);
|
||||
const mcu_pin_obj_t pin_P0_22 = PIN(P0_22, 0, 22, 0);
|
||||
const mcu_pin_obj_t pin_P0_23 = PIN(P0_23, 0, 23, 0);
|
||||
const mcu_pin_obj_t pin_P0_24 = PIN(P0_24, 0, 24, 0);
|
||||
const mcu_pin_obj_t pin_P0_25 = PIN(P0_25, 0, 25, 0);
|
||||
const mcu_pin_obj_t pin_P0_26 = PIN(P0_26, 0, 26, 0);
|
||||
const mcu_pin_obj_t pin_P0_27 = PIN(P0_27, 0, 27, 0);
|
||||
const mcu_pin_obj_t pin_P0_28 = PIN(P0_28, 0, 28, SAADC_CH_PSELP_PSELP_AnalogInput4);
|
||||
const mcu_pin_obj_t pin_P0_29 = PIN(P0_29, 0, 29, SAADC_CH_PSELP_PSELP_AnalogInput5);
|
||||
const mcu_pin_obj_t pin_P0_30 = PIN(P0_30, 0, 30, SAADC_CH_PSELP_PSELP_AnalogInput6);
|
||||
const mcu_pin_obj_t pin_P0_31 = PIN(P0_31, 0, 31, SAADC_CH_PSELP_PSELP_AnalogInput7);
|
||||
const mcu_pin_obj_t pin_P1_00 = PIN(P1_00, 1, 0, 0);
|
||||
const mcu_pin_obj_t pin_P1_01 = PIN(P1_01, 1, 1, 0);
|
||||
const mcu_pin_obj_t pin_P1_02 = PIN(P1_02, 1, 2, 0);
|
||||
const mcu_pin_obj_t pin_P1_03 = PIN(P1_03, 1, 3, 0);
|
||||
const mcu_pin_obj_t pin_P1_04 = PIN(P1_04, 1, 4, 0);
|
||||
const mcu_pin_obj_t pin_P1_05 = PIN(P1_05, 1, 5, 0);
|
||||
const mcu_pin_obj_t pin_P1_06 = PIN(P1_06, 1, 6, 0);
|
||||
const mcu_pin_obj_t pin_P1_07 = PIN(P1_07, 1, 7, 0);
|
||||
const mcu_pin_obj_t pin_P1_08 = PIN(P1_08, 1, 8, 0);
|
||||
const mcu_pin_obj_t pin_P1_09 = PIN(P1_09, 1, 9, 0);
|
||||
const mcu_pin_obj_t pin_P1_10 = PIN(P1_10, 1, 10, 0);
|
||||
const mcu_pin_obj_t pin_P1_11 = PIN(P1_11, 1, 11, 0);
|
||||
const mcu_pin_obj_t pin_P1_12 = PIN(P1_12, 1, 12, 0);
|
||||
const mcu_pin_obj_t pin_P1_13 = PIN(P1_13, 1, 13, 0);
|
||||
const mcu_pin_obj_t pin_P1_14 = PIN(P1_14, 1, 14, 0);
|
||||
const mcu_pin_obj_t pin_P1_15 = PIN(P1_15, 1, 15, 0);
|
79
ports/nrf/peripherals/nrf/nrf52840/pins.h
Normal file
79
ports/nrf/peripherals/nrf/nrf52840/pins.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by 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_NRF_PERIPHERALS_NRF52840_PINS_H
|
||||
#define MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52840_PINS_H
|
||||
|
||||
extern const mcu_pin_obj_t pin_P0_00;
|
||||
extern const mcu_pin_obj_t pin_P0_01;
|
||||
extern const mcu_pin_obj_t pin_P0_02;
|
||||
extern const mcu_pin_obj_t pin_P0_03;
|
||||
extern const mcu_pin_obj_t pin_P0_04;
|
||||
extern const mcu_pin_obj_t pin_P0_05;
|
||||
extern const mcu_pin_obj_t pin_P0_06;
|
||||
extern const mcu_pin_obj_t pin_P0_07;
|
||||
extern const mcu_pin_obj_t pin_P0_08;
|
||||
extern const mcu_pin_obj_t pin_P0_09;
|
||||
extern const mcu_pin_obj_t pin_P0_10;
|
||||
extern const mcu_pin_obj_t pin_P0_11;
|
||||
extern const mcu_pin_obj_t pin_P0_12;
|
||||
extern const mcu_pin_obj_t pin_P0_13;
|
||||
extern const mcu_pin_obj_t pin_P0_14;
|
||||
extern const mcu_pin_obj_t pin_P0_15;
|
||||
extern const mcu_pin_obj_t pin_P0_16;
|
||||
extern const mcu_pin_obj_t pin_P0_17;
|
||||
extern const mcu_pin_obj_t pin_P0_18;
|
||||
extern const mcu_pin_obj_t pin_P0_19;
|
||||
extern const mcu_pin_obj_t pin_P0_20;
|
||||
extern const mcu_pin_obj_t pin_P0_21;
|
||||
extern const mcu_pin_obj_t pin_P0_22;
|
||||
extern const mcu_pin_obj_t pin_P0_23;
|
||||
extern const mcu_pin_obj_t pin_P0_24;
|
||||
extern const mcu_pin_obj_t pin_P0_25;
|
||||
extern const mcu_pin_obj_t pin_P0_26;
|
||||
extern const mcu_pin_obj_t pin_P0_27;
|
||||
extern const mcu_pin_obj_t pin_P0_28;
|
||||
extern const mcu_pin_obj_t pin_P0_29;
|
||||
extern const mcu_pin_obj_t pin_P0_30;
|
||||
extern const mcu_pin_obj_t pin_P0_31;
|
||||
extern const mcu_pin_obj_t pin_P1_00;
|
||||
extern const mcu_pin_obj_t pin_P1_01;
|
||||
extern const mcu_pin_obj_t pin_P1_02;
|
||||
extern const mcu_pin_obj_t pin_P1_03;
|
||||
extern const mcu_pin_obj_t pin_P1_04;
|
||||
extern const mcu_pin_obj_t pin_P1_05;
|
||||
extern const mcu_pin_obj_t pin_P1_06;
|
||||
extern const mcu_pin_obj_t pin_P1_07;
|
||||
extern const mcu_pin_obj_t pin_P1_08;
|
||||
extern const mcu_pin_obj_t pin_P1_09;
|
||||
extern const mcu_pin_obj_t pin_P1_10;
|
||||
extern const mcu_pin_obj_t pin_P1_11;
|
||||
extern const mcu_pin_obj_t pin_P1_12;
|
||||
extern const mcu_pin_obj_t pin_P1_13;
|
||||
extern const mcu_pin_obj_t pin_P1_14;
|
||||
extern const mcu_pin_obj_t pin_P1_15;
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_PERIPHERALS_NRF52840_PINS_H
|
68
ports/nrf/peripherals/nrf/pins.h
Normal file
68
ports/nrf/peripherals/nrf/pins.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// DO NOT include this file directly. Use shared-bindings/microcontroller/Pin.h instead to ensure
|
||||
// that all necessary includes are already included.
|
||||
|
||||
#ifndef __MICROPY_INCLUDED_NRF_PERIPHERALS_PINS_H__
|
||||
#define __MICROPY_INCLUDED_NRF_PERIPHERALS_PINS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
// These could be squeezed to fewer bits if more fields are needed.
|
||||
uint8_t number; // port << 5 | pin number in port (0-31): 6 bits needed
|
||||
uint8_t adc_channel; // 0 is no ADC, ADC channel from 1 to 8:
|
||||
// 4 bits needed here; 5 bits used in periph registers
|
||||
} mcu_pin_obj_t;
|
||||
|
||||
extern const mp_obj_type_t mcu_pin_type;
|
||||
|
||||
// Used in device-specific pins.c
|
||||
#define PIN(p_name, p_port, p_pin, p_adc_channel) \
|
||||
{ \
|
||||
{ &mcu_pin_type }, \
|
||||
.number = NRF_GPIO_PIN_MAP(p_port, p_pin), \
|
||||
.adc_channel = (p_adc_channel), \
|
||||
}
|
||||
|
||||
// Use illegal pin value to mark unassigned pins.
|
||||
#define NO_PIN 0xff
|
||||
|
||||
// Choose based on chip, but not specifically revision (e.g., not NRF52832_XXAA)
|
||||
#ifdef NRF52832
|
||||
#include "nrf52832/pins.h"
|
||||
#endif
|
||||
|
||||
#ifdef NRF52840
|
||||
#include "nrf52840/pins.h"
|
||||
#endif
|
||||
|
||||
#endif // __MICROPY_INCLUDED_NRF_PERIPHERALS_PINS_H__
|
@ -30,7 +30,6 @@
|
||||
#include "ble_uart.h"
|
||||
#else
|
||||
#include "nrf_gpio.h"
|
||||
#include "nrf_pin.h"
|
||||
#endif
|
||||
|
||||
#if !defined( NRF52840_XXAA) || ( defined(CFG_HWUART_FOR_SERIAL) && CFG_HWUART_FOR_SERIAL == 1 )
|
||||
|
@ -130,8 +130,8 @@ uint32_t tusb_hal_millis(void) {
|
||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
|
||||
(void) itf; // interface ID, not used
|
||||
|
||||
// disconnected event
|
||||
if ( !dtr && !rts )
|
||||
// DTR = false is counted as disconnected
|
||||
if ( !dtr )
|
||||
{
|
||||
cdc_line_coding_t coding;
|
||||
tud_cdc_get_line_coding(&coding);
|
||||
|
@ -71,7 +71,7 @@ void rgb_led_status_init() {
|
||||
#else
|
||||
if (!common_hal_busio_spi_deinited(&status_apa102)) {
|
||||
// Don't use spi_deinit because that leads to infinite
|
||||
// recursion because reset_pin may call
|
||||
// recursion because reset_pin_number may call
|
||||
// rgb_led_status_init.
|
||||
spi_m_sync_disable(&status_apa102.spi_desc);
|
||||
}
|
||||
@ -103,11 +103,11 @@ void rgb_led_status_init() {
|
||||
|
||||
void reset_status_led() {
|
||||
#ifdef MICROPY_HW_NEOPIXEL
|
||||
reset_pin(MICROPY_HW_NEOPIXEL->number);
|
||||
reset_pin_number(MICROPY_HW_NEOPIXEL->number);
|
||||
#endif
|
||||
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
|
||||
reset_pin(MICROPY_HW_APA102_MOSI->number);
|
||||
reset_pin(MICROPY_HW_APA102_SCK->number);
|
||||
reset_pin_number(MICROPY_HW_APA102_MOSI->number);
|
||||
reset_pin_number(MICROPY_HW_APA102_SCK->number);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user