atmel-samd: Rework status LED implementation

* Track status pin use by user code separately so it can take over the pins and then give them back.
* Switch to hardware SPI for APA102 on Gemma and Trinket.
* Merge microcontroller/types.h into microcontroller/Pin.h to better match approach going forwards.
crypto-aes
Scott Shawcroft 6 years ago
parent 8505de1ced
commit 4a4f29b8f9

@ -3,7 +3,7 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Feather M0 Express"
#define MICROPY_HW_MCU_NAME "samd21g18"
#define MICROPY_HW_NEOPIXEL &pin_PA06
#define MICROPY_HW_NEOPIXEL (&pin_PA06)
#define SPI_FLASH_BAUDRATE (1000000)

@ -23,5 +23,6 @@ STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D11), (mp_obj_t)&pin_PA16 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D12), (mp_obj_t)&pin_PA19 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13), (mp_obj_t)&pin_PA17 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), (mp_obj_t)&pin_PA06 },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

@ -3,8 +3,10 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Gemma M0"
#define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_APA102_MOSI &pin_PA04
#define MICROPY_HW_APA102_SCK &pin_PA05
#define MICROPY_HW_APA102_MOSI (&pin_PA04)
#define MICROPY_HW_APA102_SCK (&pin_PA05)
// #define CIRCUITPY_BITBANG_APA102
#define MICROPY_PORT_A (PORT_PA04 | PORT_PA05 | PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0)

@ -5,5 +5,7 @@ STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D1), (mp_obj_t)&pin_PA02 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), (mp_obj_t)&pin_PA09 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D0), (mp_obj_t)&pin_PA08 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA05 },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

@ -6,7 +6,7 @@
#define MICROPY_HW_LED_TX PIN_PA27
#define MICROPY_HW_LED_RX PIN_PA31
#define MICROPY_HW_NEOPIXEL &pin_PA30
#define MICROPY_HW_NEOPIXEL (&pin_PA30)
#define SPI_FLASH_BAUDRATE (1000000)

@ -3,10 +3,11 @@
#define MICROPY_HW_BOARD_NAME "Adafruit Trinket M0"
#define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_APA102_MOSI &pin_PA01
#define MICROPY_HW_APA102_SCK &pin_PA00
// Rev B - Black
#define MICROPY_HW_APA102_MOSI (&pin_PA04)
#define MICROPY_HW_APA102_SCK (&pin_PA05)
#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_A (PORT_PA04 | PORT_PA05 | PORT_PA24 | PORT_PA25)
#define MICROPY_PORT_B (0)
#define AUTORESET_DELAY_MS 500

@ -7,5 +7,7 @@ STATIC const mp_map_elem_t board_global_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D4), (mp_obj_t)&pin_PA06 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D3), (mp_obj_t)&pin_PA07 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13),(mp_obj_t)&pin_PA10 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_MOSI), (mp_obj_t)&pin_PA04 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_APA102_SCK), (mp_obj_t)&pin_PA05 },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

@ -48,6 +48,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
// No ADC function on that pin
mp_raise_ValueError("Pin does not have ADC capabilities");
}
claim_pin(pin);
self->pin = pin;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
// Don't reorder these includes because they are dependencies of adc_feature.h.
// They should really be included by adc_feature.h.

@ -49,6 +49,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
mp_raise_OSError(MP_EIO);
return;
}
claim_pin(pin);
struct dac_chan_config config_analogout_chan;
dac_chan_get_config_defaults(&config_analogout_chan);

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ANALOGIO_ANALOGOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/dac/dac.h"

@ -28,7 +28,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
// Pins aren't actually defined here. They are in the board specific directory
// such as boards/arduino_zero/pins.c.

@ -77,6 +77,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
self->sda_pin = sda->pin;
self->scl_pin = scl->pin;
claim_pin(sda);
claim_pin(scl);
enum status_code status = i2c_master_init(&self->i2c_master_instance,
sercom, &config_i2c_master);

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/sercom/i2c/i2c_master.h"
#include "py/obj.h"

@ -27,6 +27,7 @@
#include "shared-bindings/busio/SPI.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "rgb_led_status.h"
#include "samd21_pins.h"
// We use ENABLE registers below we don't want to treat as a macro.
@ -53,7 +54,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) {
Sercom* potential_sercom = clock->sercom[i].sercom;
if (potential_sercom == NULL ||
#if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102)
(potential_sercom->SPI.CTRLA.bit.ENABLE != 0 &&
potential_sercom != status_apa102.spi_master_instance.hw &&
!apa102_sck_in_use)) {
#else
potential_sercom->SPI.CTRLA.bit.ENABLE != 0) {
#endif
continue;
}
clock_pinmux = PINMUX(clock->pin, (i == 0) ? MUX_C : MUX_D);
@ -122,15 +129,18 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
&config_spi_master.pinmux_pad3};
*pinmuxes[clock_pad] = clock_pinmux;
self->clock_pin = clock->pin;
claim_pin(clock);
self->MOSI_pin = NO_PIN;
if (!mosi_none) {
*pinmuxes[mosi_pad] = mosi_pinmux;
self->MOSI_pin = mosi->pin;
claim_pin(mosi);
}
self->MISO_pin = NO_PIN;
if (!miso_none) {
*pinmuxes[miso_pad] = miso_pinmux;
self->MISO_pin = miso->pin;
claim_pin(miso);
}
// Always start at 250khz which is what SD cards need. They are sensitive to

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/sercom/spi/spi.h"
#include "py/obj.h"

@ -202,6 +202,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (rx != NULL) {
*pinmuxes[rx_pad] = rx_pinmux;
self->rx_pin = rx->pin;
claim_pin(rx);
}
self->tx_pin = NO_PIN;
@ -209,6 +210,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (tx != NULL) {
*pinmuxes[tx_pad] = tx_pinmux;
self->tx_pin = tx->pin;
claim_pin(tx);
}
self->timeout_ms = timeout;
@ -217,10 +219,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->buffer_length *= (bits + 7) / 8;
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false);
if (self->buffer == NULL) {
common_hal_busio_uart_deinit(self);
mp_raise_msg(&mp_type_MemoryError, "Failed to allocate RX buffer");
}
if (usart_init(&self->uart_instance, sercom, &config_usart) != STATUS_OK) {
common_hal_busio_uart_deinit(self);
mp_raise_OSError(MP_EIO);
}

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_UART_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_UART_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/sercom/usart/usart.h"
#include "py/obj.h"

@ -31,6 +31,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "asf/sam0/drivers/port/port.h"
@ -38,6 +39,7 @@
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;
struct port_config pin_conf;
@ -50,11 +52,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
}
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
struct port_config pin_conf;
port_get_config_defaults(&pin_conf);
pin_conf.powersave = true;
port_pin_set_config(self->pin->pin, &pin_conf);
reset_pin(self->pin->pin);
}
void common_hal_digitalio_digitalinout_switch_to_input(

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"
typedef struct {

@ -26,7 +26,77 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "rgb_led_status.h"
#include "samd21_pins.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
void reset_pin(uint8_t pin) {
if (pin >= PORT_BITS) {
return;
}
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL->pin) {
neopixel_in_use = false;
rgb_led_status_init();
return;
}
#endif
#ifdef MICROPY_HW_APA102_MOSI
if (pin == MICROPY_HW_APA102_MOSI->pin ||
pin == MICROPY_HW_APA102_SCK->pin) {
apa102_mosi_in_use = apa102_mosi_in_use && pin != MICROPY_HW_APA102_MOSI->pin;
apa102_sck_in_use = apa102_sck_in_use && pin != MICROPY_HW_APA102_SCK->pin;
if (!apa102_sck_in_use && !apa102_mosi_in_use) {
rgb_led_status_init();
}
return;
}
#endif
struct system_pinmux_config config;
system_pinmux_get_config_defaults(&config);
config.powersave = true;
system_pinmux_pin_set_config(pin, &config);
}
void claim_pin(const mcu_pin_obj_t* pin) {
#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
}
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
PortGroup *const port = system_pinmux_get_group_from_gpio_pin(pin->pin);
uint32_t pin_index = (pin->pin);
PORT_PINCFG_Type state = port->PINCFG[pin_index];

@ -24,8 +24,8 @@
* THE SOFTWARE.
*/
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H__
// Don't reorder these includes because they are dependencies of adc_feature.h.
// They should really be included by adc_feature.h.
@ -70,4 +70,17 @@ typedef struct {
pin_sercom_t sercom[NUM_SERCOMS_PER_PIN];
} mcu_pin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_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
// reset_pin 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 claim_pin(const mcu_pin_obj_t* pin);
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H__

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/tc/tc.h"
#include "asf/sam0/drivers/tcc/tcc.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "asf/sam0/drivers/tc/tc.h"
#include "asf/sam0/drivers/tcc/tcc.h"

@ -189,6 +189,7 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
if (!pin->has_touch) {
mp_raise_ValueError("Invalid pin");
}
claim_pin(pin);
if (selfcap_config.num_channels > 0) {
// Deinit the touch sensor, we're going to reinitialize it.

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_TOUCHIO_TOUCHIN_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_TOUCHIO_TOUCHIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "QTouch/touch_api_ptc.h"

@ -117,6 +117,7 @@ static char *stack_top;
static char heap[16384];
void reset_mp(void) {
reset_status_led();
new_status_color(0x8f008f);
autoreset_stop();
autoreset_enable();
@ -175,10 +176,11 @@ void reset_samd21(void) {
pulsein_reset();
pulseout_reset();
// Wait for the DAC to sync.
// Wait for the DAC to sync then reset.
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
DAC->CTRLA.reg |= DAC_CTRLA_SWRST;
// Reset pins
struct system_pinmux_config config;
system_pinmux_get_config_defaults(&config);
config.powersave = true;
@ -279,6 +281,7 @@ bool start_mp(void) {
maybe_run("main.py", &result) ||
maybe_run("main.txt", &result);
}
reset_status_led();
if (result.return_code & PYEXEC_FORCED_EXIT) {
return reset_next_character;

@ -3,7 +3,9 @@
#include "mphalport.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/bitbangio/SPI.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/neopixel_write/__init__.h"
#include "shared-module/bitbangio/types.h"
@ -15,27 +17,75 @@ static uint8_t status_neopixel_color[3];
static digitalio_digitalinout_obj_t status_neopixel;
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
static uint8_t status_apa102_color[12] = {0, 0, 0, 0, 0xff, 0, 0, 0};
#ifdef CIRCUITPY_BITBANG_APA102
static bitbangio_spi_obj_t status_apa102;
#else
busio_spi_obj_t status_apa102;
#endif
#endif
#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK))
static uint32_t current_status_color = 0;
#endif
void rgb_led_status_init() {
#ifdef MICROPY_HW_NEOPIXEL
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
// Pretend we aren't using the pins. digitalio.DigitalInOut
// will mark them as used.
neopixel_in_use = false;
common_hal_digitalio_digitalinout_switch_to_output(&status_neopixel, false, DRIVE_MODE_PUSH_PULL);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_construct(&status_apa102,
MICROPY_HW_APA102_SCK,
MICROPY_HW_APA102_MOSI,
NULL);
mp_const_none);
#else
if (status_apa102.current_baudrate > 0) {
// Don't use spi_deinit because that leads to infinite
// recursion because reset_pin may call
// rgb_led_status_init.
spi_disable(&status_apa102.spi_master_instance);
}
common_hal_busio_spi_construct(&status_apa102,
MICROPY_HW_APA102_SCK,
MICROPY_HW_APA102_MOSI,
mp_const_none);
#endif
// Pretend we aren't using the pins. bitbangio.SPI will
// mark them as used.
apa102_mosi_in_use = false;
apa102_sck_in_use = false;
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_try_lock(&status_apa102);
shared_module_bitbangio_spi_configure(&status_apa102, 100000, 0, 1, 8);
#else
common_hal_busio_spi_try_lock(&status_apa102);
common_hal_busio_spi_configure(&status_apa102, 100000, 0, 1, 8);
#endif
#endif
#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK))
// Force a write of the current status color.
uint32_t rgb = current_status_color;
current_status_color = 0;
new_status_color(rgb);
#endif
}
void reset_status_led() {
#ifdef MICROPY_HW_NEOPIXEL
reset_pin(MICROPY_HW_NEOPIXEL->pin);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
reset_pin(MICROPY_HW_APA102_MOSI->pin);
reset_pin(MICROPY_HW_APA102_SCK->pin);
#endif
}
@ -48,27 +98,48 @@ void new_status_color(uint32_t rgb) {
#endif
#ifdef MICROPY_HW_NEOPIXEL
if (neopixel_in_use) {
return;
}
status_neopixel_color[0] = (rgb >> 8) & 0xff;
status_neopixel_color[1] = (rgb >> 16) & 0xff;
status_neopixel_color[2] = rgb & 0xff;
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
if (apa102_mosi_in_use || apa102_sck_in_use) {
return;
}
status_apa102_color[5] = rgb & 0xff;
status_apa102_color[6] = (rgb >> 8) & 0xff;
status_apa102_color[7] = (rgb >> 16) & 0xff;
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
#else
common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
#endif
#endif
}
void temp_status_color(uint32_t rgb) {
#ifdef MICROPY_HW_NEOPIXEL
if (neopixel_in_use) {
return;
}
uint8_t colors[3] = {(rgb >> 8) & 0xff, (rgb >> 16) & 0xff, rgb & 0xff};
common_hal_neopixel_write(&status_neopixel, colors, 3);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
if (apa102_mosi_in_use || apa102_sck_in_use) {
return;
}
uint8_t colors[12] = {0, 0, 0, 0, 0xff, rgb & 0xff, (rgb >> 8) & 0xff, (rgb >> 16) & 0xff, 0x0, 0x0, 0x0, 0x0};
shared_module_bitbangio_spi_write(&status_apa102, colors, 8);
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_write(&status_apa102, colors, 12);
#else
common_hal_busio_spi_write(&status_apa102, colors, 12);
#endif
#endif
}
@ -77,7 +148,11 @@ void clear_temp_status() {
common_hal_neopixel_write(&status_neopixel, status_neopixel_color, 3);
#endif
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 12);
#ifdef CIRCUITPY_BITBANG_APA102
shared_module_bitbangio_spi_write(&status_apa102, status_apa102_color, 8);
#else
common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8);
#endif
#endif
}

@ -4,12 +4,19 @@
#include <stdint.h>
#include <stdbool.h>
#include "mpconfigport.h"
#include "rgb_led_colors.h"
extern void rgb_led_status_init(void);
extern void new_status_color(uint32_t rgb);
extern void temp_status_color(uint32_t rgb);
extern void clear_temp_status(void);
#if defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK) && !defined(CIRCUITPY_BITBANG_APA102)
#include "common-hal/busio/SPI.h"
extern busio_spi_obj_t status_apa102;
#endif
void rgb_led_status_init(void);
void reset_status_led(void);
void new_status_color(uint32_t rgb);
void temp_status_color(uint32_t rgb);
void clear_temp_status(void);
uint32_t color_brightness(uint32_t color, uint8_t brightness);

@ -66,16 +66,6 @@ const mcu_pin_obj_t pin_## p_name = { \
#define NO_ADC_INPUT (0)
void reset_pin(uint8_t pin) {
if (pin >= PORT_BITS) {
return;
}
struct system_pinmux_config config;
system_pinmux_get_config_defaults(&config);
config.powersave = true;
system_pinmux_pin_set_config(pin, &config);
}
// Pins in datasheet order.
// NOTE(tannewt): TC wave out 0 is commented out because the first channel is
// used to vary the 16 bit timer's frequency.

@ -1,7 +1,7 @@
#ifndef __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_SAMD21_PINS_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_BOARDS_SAMD21_PINS_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
void reset_pin(uint8_t pin);

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_ANALOGIO_ANALOGIN_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_ANALOGIO_ANALOGIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"

@ -28,7 +28,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
// Pins aren't actually defined here. They are in the board specific directory
// such as boards/feather_huzzah/pins.c.

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_BUSIO_SPI_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_BUSIO_SPI_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_BUSIO_UART_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_BUSIO_UART_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_DIGITALIO_DIGITALINOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"
typedef struct {

@ -27,6 +27,16 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PIN_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PIN_H__
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
qstr name;
uint8_t gpio_number;
uint8_t gpio_function;
uint32_t peripheral;
} mcu_pin_obj_t;
// Magic values for gpio_number.
#define NO_GPIO 0xff
#define SPECIAL_CASE 0xfe

@ -25,7 +25,7 @@
*/
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "eagle_soc.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER___INIT___H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER___INIT___H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
extern const mcu_pin_obj_t pin_TOUT;
extern const mcu_pin_obj_t pin_XPD_DCDC;

@ -1,40 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft
*
* 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_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__
#define __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
qstr name;
uint8_t gpio_number;
uint8_t gpio_function;
uint32_t peripheral;
} mcu_pin_obj_t;
#endif // __MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_TYPES_H__

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_ESP8266_COMMON_HAL_PULSEIO_PWMOUT_H__
#define __MICROPY_INCLUDED_ESP8266_COMMON_HAL_PULSEIO_PWMOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
typedef struct {
mp_obj_base_t base;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_ANALOGIO_ANALOGIN_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_ANALOGIO_ANALOGIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogIn.h"
extern const mp_obj_type_t analogio_analogin_type;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_ANALOGIO_ANALOGOUT_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_ANALOGIO_ANALOGOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogOut.h"
extern const mp_obj_type_t analogio_analogout_type;

@ -29,7 +29,7 @@
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/bitbangio/types.h"
// Type object used in Python. Should be shared between ports.

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_BITBANGIO_ONEWIRE_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_BITBANGIO_ONEWIRE_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/bitbangio/types.h"
extern const mp_obj_type_t bitbangio_onewire_type;

@ -29,7 +29,7 @@
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/bitbangio/types.h"
// Type object used in Python. Should be shared between ports.

@ -36,7 +36,7 @@
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/busio/I2C.h"
// Type object used in Python. Should be shared between ports.

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_ONEWIRE_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_ONEWIRE_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/busio/OneWire.h"
extern const mp_obj_type_t busio_onewire_type;

@ -29,7 +29,7 @@
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/busio/SPI.h"
// Type object used in Python. Should be shared between ports.

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_UART_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_UART_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/busio/UART.h"
extern const mp_obj_type_t busio_uart_type;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_DIGITALIO_DIGITALINOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/digitalio/DigitalInOut.h"
extern const mp_obj_type_t digitalio_digitalinout_type;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"
// Type object used in Python. Should be shared between ports.

@ -34,7 +34,7 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "py/runtime.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PWMOUT_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PWMOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PWMOut.h"
extern const mp_obj_type_t pulseio_pwmout_type;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PULSEIN_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PULSEIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PulseIn.h"
extern const mp_obj_type_t pulseio_pulsein_type;

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PULSEOUT_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PULSEOUT_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/pulseio/PulseOut.h"
#include "common-hal/pulseio/PWMOut.h"

@ -27,7 +27,7 @@
#ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_TOUCHIO_TOUCHIN_H__
#define __MICROPY_INCLUDED_SHARED_BINDINGS_TOUCHIO_TOUCHIN_H__
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/touchio/TouchIn.h"
extern const mp_obj_type_t touchio_touchin_type;

@ -29,7 +29,7 @@
#include "py/mperrno.h"
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-module/bitbangio/types.h"

@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/bitbangio/OneWire.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/digitalio/DigitalInOut.h"

@ -29,7 +29,7 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-module/bitbangio/types.h"

@ -25,7 +25,7 @@
*/
// Wraps the bitbangio implementation of OneWire for use in busio.
#include "common-hal/microcontroller/types.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/bitbangio/OneWire.h"
#include "shared-module/busio/OneWire.h"

Loading…
Cancel
Save