codeformat: Fix handling of `**`

After discussing with danh, I noticed that `a/**/b` would not match `a/b`.

After correcting this and re-running "pre-commit run --all", additional
files were reindented, including the codeformat script itself.
This commit is contained in:
Jeff Epler 2021-04-30 15:30:13 -05:00
parent e95e921ca1
commit dfa7c3d32d
22 changed files with 431 additions and 427 deletions

View File

@ -76,22 +76,22 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
STATIC int usage(char **argv) {
printf(
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
"Options:\n"
"--version : show version information\n"
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
"-v : verbose (trace various operations); can be multiple\n"
"-O[N] : apply bytecode optimizations of level N\n"
"\n"
"Target specific options:\n"
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
"-mno-unicode : don't support unicode in compiled strings\n"
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
"-march=<arch> : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n"
"\n"
"Implementation specific options:\n", argv[0]
);
"usage: %s [<opts>] [-X <implopt>] <input filename>\n"
"Options:\n"
"--version : show version information\n"
"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n"
"-s : source filename to embed in the compiled bytecode (defaults to input file)\n"
"-v : verbose (trace various operations); can be multiple\n"
"-O[N] : apply bytecode optimizations of level N\n"
"\n"
"Target specific options:\n"
"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n"
"-mno-unicode : don't support unicode in compiled strings\n"
"-mcache-lookup-bc : cache map lookups in the bytecode\n"
"-march=<arch> : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n"
"\n"
"Implementation specific options:\n", argv[0]
);
int impl_opts_cnt = 0;
printf(
" emit={bytecode,native,viper} -- set the default code emitter\n"

View File

@ -7,9 +7,9 @@
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PA06 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PA06 1
#define IGNORE_PIN_PA12 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA20 1

View File

@ -41,7 +41,7 @@ typedef struct {
uint8_t sda_pin;
} busio_i2c_obj_t;
extern Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda,
uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux);
extern Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H

View File

@ -55,14 +55,14 @@ static void usart_async_rxc_callback(const struct usart_async_descriptor *const
}
void common_hal_busio_uart_construct(busio_uart_obj_t *self,
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx,
const mcu_pin_obj_t * rts, const mcu_pin_obj_t * cts,
const mcu_pin_obj_t * rs485_dir, bool rs485_invert,
const mcu_pin_obj_t *tx, const mcu_pin_obj_t *rx,
const mcu_pin_obj_t *rts, const mcu_pin_obj_t *cts,
const mcu_pin_obj_t *rs485_dir, bool rs485_invert,
uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop,
mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer,
mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer,
bool sigint_enabled) {
Sercom* sercom = NULL;
Sercom *sercom = NULL;
uint8_t sercom_index = 255; // Unset index
uint32_t rx_pinmux = 0;
uint8_t rx_pad = 255; // Unset pad
@ -88,29 +88,29 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
self->timeout_ms = timeout * 1000;
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) {
Sercom* potential_sercom = NULL;
Sercom *potential_sercom = NULL;
if (have_tx) {
sercom_index = tx->sercom[i].index;
if (sercom_index >= SERCOM_INST_NUM) {
continue;
}
potential_sercom = sercom_insts[sercom_index];
#ifdef SAMD21
if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 ||
#ifdef SAMD21
if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 ||
!(tx->sercom[i].pad == 0 ||
tx->sercom[i].pad == 2)) {
continue;
}
#endif
#ifdef SAM_D5X_E5X
if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 ||
#endif
#ifdef SAM_D5X_E5X
if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 ||
!(tx->sercom[i].pad == 0)) {
continue;
}
#endif
#endif
tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D);
tx_pad = tx->sercom[i].pad;
if (rx == NULL) {
@ -158,7 +158,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// self->buffer, so do it manually. (However, as long as internal
// pointers like this are NOT moved, allocating the buffer
// in the long-lived pool is not strictly necessary)
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
if (self->buffer == NULL) {
common_hal_busio_uart_deinit(self);
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), self->buffer_length * sizeof(uint8_t));
@ -191,24 +191,24 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// Doing a group mask and set of the registers saves 60 bytes over setting the bitfields individually.
sercom->USART.CTRLA.reg &= ~(SERCOM_USART_CTRLA_TXPO_Msk |
SERCOM_USART_CTRLA_RXPO_Msk |
SERCOM_USART_CTRLA_FORM_Msk);
SERCOM_USART_CTRLA_RXPO_Msk |
SERCOM_USART_CTRLA_FORM_Msk);
sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) |
SERCOM_USART_CTRLA_RXPO(rx_pad) |
(parity == BUSIO_UART_PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
SERCOM_USART_CTRLA_RXPO(rx_pad) |
(parity == BUSIO_UART_PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1));
// Enable tx and/or rx based on whether the pins were specified.
// CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that.
sercom->USART.CTRLB.reg &= ~(SERCOM_USART_CTRLB_TXEN |
SERCOM_USART_CTRLB_RXEN |
SERCOM_USART_CTRLB_PMODE |
SERCOM_USART_CTRLB_SBMODE |
SERCOM_USART_CTRLB_CHSIZE_Msk);
SERCOM_USART_CTRLB_RXEN |
SERCOM_USART_CTRLB_PMODE |
SERCOM_USART_CTRLB_SBMODE |
SERCOM_USART_CTRLB_CHSIZE_Msk);
sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) |
(have_rx ? SERCOM_USART_CTRLB_RXEN : 0) |
(parity == BUSIO_UART_PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) |
(stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) |
SERCOM_USART_CTRLB_CHSIZE(bits % 8);
(have_rx ? SERCOM_USART_CTRLB_RXEN : 0) |
(parity == BUSIO_UART_PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) |
(stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) |
SERCOM_USART_CTRLB_CHSIZE(bits % 8);
// Set baud rate
common_hal_busio_uart_set_baudrate(self, baudrate);
@ -227,7 +227,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
gpio_set_pin_direction(tx->number, GPIO_DIRECTION_OUT);
gpio_set_pin_pull_mode(tx->number, GPIO_PULL_OFF);
gpio_set_pin_function(tx->number, tx_pinmux);
self->tx_pin = tx->number;
self->tx_pin = tx->number;
claim_pin(tx);
} else {
self->tx_pin = NO_PIN;
@ -237,7 +237,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
gpio_set_pin_direction(rx->number, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(rx->number, GPIO_PULL_OFF);
gpio_set_pin_function(rx->number, rx_pinmux);
self->rx_pin = rx->number;
self->rx_pin = rx->number;
claim_pin(rx);
} else {
self->rx_pin = NO_PIN;
@ -255,7 +255,7 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
return;
}
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
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_number(self->rx_pin);
@ -271,7 +271,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
}
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
if (len == 0) {
// Nothing to read.
@ -328,7 +328,7 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
}
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
struct io_descriptor *io;
usart_async_get_io_descriptor(usart_desc_p, &io);
@ -359,21 +359,21 @@ uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) {
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
usart_async_set_baud_rate(usart_desc_p,
// Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in
// hpl_sercom_config.h.
_usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud
PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY,
16, // samples
USART_BAUDRATE_ASYNCH_ARITHMETIC,
0 // fraction - not used for ARITHMETIC
));
// Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in
// hpl_sercom_config.h.
_usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud
PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY,
16, // samples
USART_BAUDRATE_ASYNCH_ARITHMETIC,
0 // fraction - not used for ARITHMETIC
));
self->baudrate = baudrate;
}
mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self) {
return (mp_float_t) (self->timeout_ms / 1000.0f);
return (mp_float_t)(self->timeout_ms / 1000.0f);
}
void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeout) {
@ -382,7 +382,7 @@ void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeou
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
struct usart_async_status async_status;
usart_async_get_status(usart_desc_p, &async_status);
return async_status.rxcnt;
@ -390,7 +390,7 @@ uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
usart_async_flush_rx_buffer(usart_desc_p);
}
@ -401,7 +401,7 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
return false;
}
// This assignment is only here because the usart_async routines take a *const argument.
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc;
struct usart_async_status async_status;
usart_async_get_status(usart_desc_p, &async_status);
return !(async_status.flags & USART_ASYNC_STATUS_BUSY);

View File

@ -36,8 +36,8 @@
#include "peripherals/samd/sercom.h"
void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self,
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *addresses, unsigned int num_addresses, bool smbus) {
const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda,
uint8_t *addresses, unsigned int num_addresses, bool smbus) {
uint8_t sercom_index;
uint32_t sda_pinmux, scl_pinmux;
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
@ -58,12 +58,13 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
samd_peripherals_sercom_clock_init(sercom, sercom_index);
#ifdef SAM_D5X_E5X
#ifdef SAM_D5X_E5X
sercom->I2CS.CTRLC.bit.SDASETUP = 0x08;
#endif
#endif
sercom->I2CS.CTRLA.bit.SWRST = 1;
while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) {}
while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) {
}
sercom->I2CS.CTRLB.bit.AACKEN = 0; // Automatic acknowledge is disabled.
@ -134,8 +135,7 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self,
return -err;
}
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart)
{
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) {
int err = i2c_peripheral_check_error(self, false);
if (err) {
return err;

View File

@ -44,7 +44,7 @@ void reset_all_pins(void);
// need to store a full pointer.
void reset_pin_number(uint8_t pin_number);
void never_reset_pin_number(uint8_t pin_number);
void claim_pin(const mcu_pin_obj_t* pin);
void claim_pin(const mcu_pin_obj_t *pin);
bool pin_number_is_free(uint8_t pin_number);
typedef struct {

View File

@ -83,11 +83,11 @@
STATIC float convert_dec_to_frac(uint8_t val) {
float float_val = (float)val;
if (val < 10) {
return (float_val/10.0);
return float_val / 10.0;
} else if (val < 100) {
return (float_val/100.0);
return float_val / 100.0;
} else {
return (float_val/1000.0);
return float_val / 1000.0;
}
}
@ -134,17 +134,17 @@ STATIC float calculate_temperature(uint16_t raw_value) {
tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec);
tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec);
INT1VR = 1 - ((float)room_int1v_val/INT1V_DIVIDER_1000);
INT1VH = 1 - ((float)hot_int1v_val/INT1V_DIVIDER_1000);
INT1VR = 1 - ((float)room_int1v_val / INT1V_DIVIDER_1000);
INT1VH = 1 - ((float)hot_int1v_val / INT1V_DIVIDER_1000);
VADCR = ((float)ADCR * INT1VR)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
VADCH = ((float)ADCH * INT1VH)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
VADCR = ((float)ADCR * INT1VR) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
VADCH = ((float)ADCH * INT1VH) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */
float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */
float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
VADC = ((float)raw_value * INT1V_VALUE_FLOAT)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
VADC = ((float)raw_value * INT1V_VALUE_FLOAT) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
// Hopefully compiler will remove common subepxressions here.
@ -152,15 +152,15 @@ STATIC float calculate_temperature(uint16_t raw_value) {
// 1b as mentioned in data sheet section "Temperature Sensor Characteristics"
// of Electrical Characteristics. (adapted from ASF sample code).
// Coarse Temp Calculation by assume INT1V=1V for this ADC conversion
float coarse_temp = tempR + (((tempH - tempR)/(VADCH - VADCR)) * (VADC - VADCR));
float coarse_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADC - VADCR));
// Calculation to find the real INT1V value during the ADC conversion
INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR))/(tempH - tempR));
INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR));
VADCM = ((float)raw_value * INT1VM)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
VADCM = ((float)raw_value * INT1VM) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
// Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion
float fine_temp = tempR + (((tempH - tempR)/(VADCH - VADCR)) * (VADCM - VADCR));
float fine_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADCM - VADCR));
return fine_temp;
}
@ -183,17 +183,17 @@ STATIC float calculate_temperature(uint16_t TP, uint16_t TC) {
uint16_t VCH = (*(uint32_t *)FUSES_HOT_ADC_VAL_CTAT_ADDR & FUSES_HOT_ADC_VAL_CTAT_Msk) >> FUSES_HOT_ADC_VAL_CTAT_Pos;
// From SAMD51 datasheet: section 45.6.3.1 (page 1327).
return (TL*VPH*TC - VPL*TH*TC - TL*VCH*TP + TH*VCL*TP) / (VCL*TP - VCH*TP - VPL*TC + VPH*TC);
return (TL * VPH * TC - VPL * TH * TC - TL * VCH * TP + TH * VCL * TP) / (VCL * TP - VCH * TP - VPL * TC + VPH * TC);
}
#endif // SAMD51
float common_hal_mcu_processor_get_temperature(void) {
struct adc_sync_descriptor adc;
static Adc* adc_insts[] = ADC_INSTS;
static Adc *adc_insts[] = ADC_INSTS;
samd_peripherals_adc_setup(&adc, adc_insts[0]);
#ifdef SAMD21
#ifdef SAMD21
// The parameters chosen here are from the temperature example in:
// http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf
// That note also recommends in general:
@ -205,9 +205,9 @@ float common_hal_mcu_processor_get_temperature(void) {
// Channel arg is ignored.
adc_sync_enable_channel(&adc, IGNORED_CHANNEL);
adc_sync_set_inputs(&adc,
ADC_INPUTCTRL_MUXPOS_TEMP_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
ADC_INPUTCTRL_MUXPOS_TEMP_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
hri_adc_write_CTRLB_PRESCALER_bf(adc.device.hw, ADC_CTRLB_PRESCALER_DIV32_Val);
hri_adc_write_SAMPCTRL_SAMPLEN_bf(adc.device.hw, ADC_TEMP_SAMPLE_LENGTH);
@ -227,14 +227,14 @@ float common_hal_mcu_processor_get_temperature(void) {
// Empirical observation shows the first reading is quite different than subsequent ones.
// Channel arg is ignored.
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &value), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &value), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&value), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&value), 2);
adc_sync_deinit(&adc);
return calculate_temperature(value);
#endif // SAMD21
#endif // SAMD21
#ifdef SAM_D5X_E5X
#ifdef SAM_D5X_E5X
adc_sync_set_resolution(&adc, ADC_CTRLB_RESSEL_12BIT_Val);
// Using INTVCC0 as the reference voltage.
// INTVCC1 seems to read a little high.
@ -250,48 +250,48 @@ float common_hal_mcu_processor_get_temperature(void) {
// Channel arg is ignored.
adc_sync_enable_channel(&adc, IGNORED_CHANNEL);
adc_sync_set_inputs(&adc,
ADC_INPUTCTRL_MUXPOS_PTAT_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
ADC_INPUTCTRL_MUXPOS_PTAT_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
// Read both temperature sensors.
volatile uint16_t ptat;
volatile uint16_t ctat;
// Read twice for stability (necessary?).
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ptat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ptat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ptat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ptat), 2);
adc_sync_set_inputs(&adc,
ADC_INPUTCTRL_MUXPOS_CTAT_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
ADC_INPUTCTRL_MUXPOS_CTAT_Val, // pos_input
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored)
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ctat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ctat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ctat), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ctat), 2);
// Turn off temp sensor.
hri_supc_clear_VREF_TSEN_bit(SUPC);
adc_sync_deinit(&adc);
return calculate_temperature(ptat, ctat);
#endif // SAMD51
#endif // SAMD51
}
float common_hal_mcu_processor_get_voltage(void) {
#if MICROCONTROLLER_VOLTAGE_DISABLE
#if MICROCONTROLLER_VOLTAGE_DISABLE
return NAN;
#else
#else
struct adc_sync_descriptor adc;
static Adc* adc_insts[] = ADC_INSTS;
static Adc *adc_insts[] = ADC_INSTS;
samd_peripherals_adc_setup(&adc, adc_insts[0]);
#ifdef SAMD21
#ifdef SAMD21
adc_sync_set_reference(&adc, ADC_REFCTRL_REFSEL_INT1V_Val);
#endif
#endif
#ifdef SAM_D5X_E5X
#ifdef SAM_D5X_E5X
hri_supc_set_VREF_SEL_bf(SUPC, SUPC_VREF_SEL_1V0_Val);
hri_supc_set_VREF_VREFOE_bit(SUPC);
@ -302,14 +302,14 @@ float common_hal_mcu_processor_get_voltage(void) {
// startup time. There is no synchronization bit to check.
// See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference
mp_hal_delay_ms(1);
#endif
#endif
adc_sync_set_resolution(&adc, ADC_CTRLB_RESSEL_12BIT_Val);
// Channel arg is ignored.
adc_sync_set_inputs(&adc,
ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC_Val, // IOVCC/4 (nominal 3.3V/4)
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored).
ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC_Val, // IOVCC/4 (nominal 3.3V/4)
ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input
IGNORED_CHANNEL); // channel (ignored).
adc_sync_enable_channel(&adc, IGNORED_CHANNEL);
volatile uint16_t reading;
@ -320,13 +320,13 @@ float common_hal_mcu_processor_get_voltage(void) {
// "Discard the first conversion result whenever there is a change in ADC configuration
// like voltage reference / ADC channel change"
// Empirical observation shows the first reading is quite different than subsequent ones.
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &reading), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &reading), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&reading), 2);
adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&reading), 2);
adc_sync_deinit(&adc);
// Multiply by 4 to compensate for SCALEDIOVCC division by 4.
return (reading / 4095.0f) * 4.0f;
#endif
#endif
}
uint32_t common_hal_mcu_processor_get_frequency(void) {
@ -336,16 +336,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
#ifdef SAMD21
uint32_t* id_addresses[4] = {(uint32_t *) 0x0080A00C, (uint32_t *) 0x0080A040,
(uint32_t *) 0x0080A044, (uint32_t *) 0x0080A048};
uint32_t *id_addresses[4] = {(uint32_t *)0x0080A00C, (uint32_t *)0x0080A040,
(uint32_t *)0x0080A044, (uint32_t *)0x0080A048};
#endif
#ifdef SAM_D5X_E5X
uint32_t* id_addresses[4] = {(uint32_t *) 0x008061FC, (uint32_t *) 0x00806010,
(uint32_t *) 0x00806014, (uint32_t *) 0x00806018};
uint32_t *id_addresses[4] = {(uint32_t *)0x008061FC, (uint32_t *)0x00806010,
(uint32_t *)0x00806014, (uint32_t *)0x00806018};
#endif
for (int i=0; i<4; i++) {
for (int k=0; k<4; k++) {
for (int i = 0; i < 4; i++) {
for (int k = 0; k < 4; k++) {
raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff;
}
}

View File

@ -99,296 +99,296 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
.type = &nvm_bytearray_type,
},
.len = CIRCUITPY_INTERNAL_NVM_SIZE,
.start_address = (uint8_t*) (CIRCUITPY_INTERNAL_NVM_START_ADDR)
.start_address = (uint8_t *)(CIRCUITPY_INTERNAL_NVM_START_ADDR)
};
#endif
// This maps MCU pin names to pin objects.
STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
#if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00)
#if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00)
{ MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) },
#endif
#if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01)
#endif
#if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01)
{ MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) },
#endif
#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
#endif
#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
{ MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) },
#endif
#if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03)
#endif
#if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03)
{ MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) },
#endif
#if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04)
#endif
#if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04)
{ MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) },
#endif
#if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
#endif
#if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
{ MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) },
#endif
#if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06)
#endif
#if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06)
{ MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) },
#endif
#if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07)
#endif
#if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07)
{ MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) },
#endif
#if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08)
#endif
#if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08)
{ MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) },
#endif
#if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09)
#endif
#if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09)
{ MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) },
#endif
#if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10)
#endif
#if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10)
{ MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) },
#endif
#if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11)
#endif
#if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11)
{ MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) },
#endif
#if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12)
#endif
#if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12)
{ MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) },
#endif
#if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13)
#endif
#if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13)
{ MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) },
#endif
#if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14)
#endif
#if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14)
{ MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) },
#endif
#if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15)
#endif
#if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15)
{ MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) },
#endif
#if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16)
#endif
#if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16)
{ MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) },
#endif
#if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17)
#endif
#if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17)
{ MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) },
#endif
#if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18)
#endif
#if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18)
{ MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) },
#endif
#if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19)
#endif
#if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19)
{ MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) },
#endif
#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20)
#endif
#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20)
{ MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) },
#endif
#if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21)
#endif
#if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21)
{ MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) },
#endif
#if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22)
#endif
#if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22)
{ MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) },
#endif
#if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23)
#endif
#if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23)
{ MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) },
#endif
#if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24)
#endif
#if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24)
{ MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) },
#endif
#if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25)
#endif
#if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25)
{ MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) },
#endif
#if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27)
#endif
#if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27)
{ MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) },
#endif
#if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28)
#endif
#if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28)
{ MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) },
#endif
#if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30)
#endif
#if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30)
{ MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) },
#endif
#if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31)
#endif
#if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31)
{ MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) },
#endif
#endif
#if defined(PIN_PB00) && !defined(IGNORE_PIN_PB00)
#if defined(PIN_PB00) && !defined(IGNORE_PIN_PB00)
{ MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) },
#endif
#if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01)
#endif
#if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01)
{ MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) },
#endif
#if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02)
#endif
#if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02)
{ MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) },
#endif
#if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03)
#endif
#if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03)
{ MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) },
#endif
#if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04)
#endif
#if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04)
{ MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) },
#endif
#if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05)
#endif
#if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05)
{ MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) },
#endif
#if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06)
#endif
#if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06)
{ MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) },
#endif
#if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07)
#endif
#if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07)
{ MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) },
#endif
#if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08)
#endif
#if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08)
{ MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) },
#endif
#if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09)
#endif
#if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09)
{ MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) },
#endif
#if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10)
#endif
#if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10)
{ MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) },
#endif
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
#endif
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
{ MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) },
#endif
#if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12)
#endif
#if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12)
{ MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) },
#endif
#if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13)
#endif
#if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13)
{ MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) },
#endif
#if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14)
#endif
#if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14)
{ MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) },
#endif
#if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15)
#endif
#if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15)
{ MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) },
#endif
#if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16)
#endif
#if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16)
{ MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) },
#endif
#if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17)
#endif
#if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17)
{ MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) },
#endif
#if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18)
#endif
#if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18)
{ MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) },
#endif
#if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19)
#endif
#if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19)
{ MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) },
#endif
#if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20)
#endif
#if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20)
{ MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) },
#endif
#if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21)
#endif
#if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21)
{ MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) },
#endif
#if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22)
#endif
#if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22)
{ MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) },
#endif
#if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23)
#endif
#if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23)
{ MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) },
#endif
#if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30)
#endif
#if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30)
{ MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) },
#endif
#if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31)
#endif
#if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31)
{ MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) },
#endif
#endif
#if defined(PIN_PC00) && !defined(IGNORE_PIN_PC00)
#if defined(PIN_PC00) && !defined(IGNORE_PIN_PC00)
{ MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) },
#endif
#if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01)
#endif
#if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01)
{ MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) },
#endif
#if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02)
#endif
#if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02)
{ MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) },
#endif
#if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03)
#endif
#if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03)
{ MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) },
#endif
#if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04)
#endif
#if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04)
{ MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) },
#endif
#if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05)
#endif
#if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05)
{ MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) },
#endif
#if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06)
#endif
#if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06)
{ MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) },
#endif
#if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07)
#endif
#if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07)
{ MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) },
#endif
#if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10)
#endif
#if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10)
{ MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) },
#endif
#if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11)
#endif
#if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11)
{ MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) },
#endif
#if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12)
#endif
#if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12)
{ MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) },
#endif
#if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13)
#endif
#if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13)
{ MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) },
#endif
#if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14)
#endif
#if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14)
{ MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) },
#endif
#if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15)
#endif
#if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15)
{ MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) },
#endif
#if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16)
#endif
#if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16)
{ MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) },
#endif
#if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17)
#endif
#if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17)
{ MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) },
#endif
#if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18)
#endif
#if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18)
{ MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) },
#endif
#if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19)
#endif
#if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19)
{ MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) },
#endif
#if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20)
#endif
#if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20)
{ MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) },
#endif
#if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21)
#endif
#if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21)
{ MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) },
#endif
#if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22)
#endif
#if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22)
{ MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) },
#endif
#if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23)
#endif
#if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23)
{ MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) },
#endif
#if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24)
#endif
#if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24)
{ MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) },
#endif
#if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25)
#endif
#if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25)
{ MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) },
#endif
#if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26)
#endif
#if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26)
{ MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) },
#endif
#if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27)
#endif
#if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27)
{ MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) },
#endif
#if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28)
#endif
#if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28)
{ MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) },
#endif
#if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30)
#endif
#if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30)
{ MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) },
#endif
#if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31)
#endif
#if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31)
{ MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) },
#endif
#endif
#if defined(PIN_PD00) && !defined(IGNORE_PIN_PD00)
#if defined(PIN_PD00) && !defined(IGNORE_PIN_PD00)
{ MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_PD00) },
#endif
#if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01)
#endif
#if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01)
{ MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) },
#endif
#if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08)
#endif
#if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08)
{ MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) },
#endif
#if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09)
#endif
#if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09)
{ MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) },
#endif
#if defined(PIN_PD10) && !defined(IGNORE_PIN_PD10)
#endif
#if defined(PIN_PD10) && !defined(IGNORE_PIN_PD10)
{ MP_ROM_QSTR(MP_QSTR_PD10), MP_ROM_PTR(&pin_PD10) },
#endif
#if defined(PIN_PD11) && !defined(IGNORE_PIN_PD11)
#endif
#if defined(PIN_PD11) && !defined(IGNORE_PIN_PD11)
{ MP_ROM_QSTR(MP_QSTR_PD11), MP_ROM_PTR(&pin_PD11) },
#endif
#if defined(PIN_PD12) && !defined(IGNORE_PIN_PD12)
#endif
#if defined(PIN_PD12) && !defined(IGNORE_PIN_PD12)
{ MP_ROM_QSTR(MP_QSTR_PD12), MP_ROM_PTR(&pin_PD12) },
#endif
#if defined(PIN_PD20) && !defined(IGNORE_PIN_PD20)
#endif
#if defined(PIN_PD20) && !defined(IGNORE_PIN_PD20)
{ MP_ROM_QSTR(MP_QSTR_PD20), MP_ROM_PTR(&pin_PD20) },
#endif
#if defined(PIN_PD21) && !defined(IGNORE_PIN_PD21)
#endif
#if defined(PIN_PD21) && !defined(IGNORE_PIN_PD21)
{ MP_ROM_QSTR(MP_QSTR_PD21), MP_ROM_PTR(&pin_PD21) },
#endif
#endif
};
MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table);

View File

@ -54,16 +54,20 @@ volatile static uint32_t overflow_count = 0;
volatile static uint32_t start_overflow = 0;
void pulsein_timer_interrupt_handler(uint8_t index) {
if (index != pulsein_tc_index) return;
if (index != pulsein_tc_index) {
return;
}
overflow_count++;
Tc* tc = tc_insts[index];
if (!tc->COUNT16.INTFLAG.bit.OVF) return;
Tc *tc = tc_insts[index];
if (!tc->COUNT16.INTFLAG.bit.OVF) {
return;
}
// Clear the interrupt bit.
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_OVF;
}
static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) {
static void pulsein_set_config(pulseio_pulsein_obj_t *self, bool first_edge) {
uint32_t sense_setting;
if (!first_edge) {
sense_setting = EIC_CONFIG_SENSE0_BOTH_Val;
@ -83,16 +87,17 @@ void pulsein_interrupt_handler(uint8_t channel) {
common_hal_mcu_disable_interrupts();
// Grab the current time first.
uint32_t current_overflow = overflow_count;
Tc* tc = tc_insts[pulsein_tc_index];
Tc *tc = tc_insts[pulsein_tc_index];
#ifdef SAM_D5X_E5X
tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_READSYNC;
while (tc->COUNT16.SYNCBUSY.bit.COUNT == 1 ||
tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) {}
tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) {
}
#endif
uint32_t current_count = tc->COUNT16.COUNT.reg;
pulseio_pulsein_obj_t* self = get_eic_channel_data(channel);
if (self->len == 0 ) {
pulseio_pulsein_obj_t *self = get_eic_channel_data(channel);
if (self->len == 0) {
start_overflow = overflow_count;
}
if (self->first_edge) {
@ -114,7 +119,7 @@ void pulsein_interrupt_handler(uint8_t channel) {
if (total_diff < duration) {
duration = total_diff;
}
//check if the input is taking too long, 15 timer overflows is approx 1 second
// check if the input is taking too long, 15 timer overflows is approx 1 second
if (current_overflow - start_overflow > 15) {
self->errored_too_fast = true;
common_hal_pulseio_pulsein_pause(self);
@ -136,16 +141,16 @@ void pulsein_interrupt_handler(uint8_t channel) {
}
void pulsein_reset() {
#ifdef SAMD21
#ifdef SAMD21
rtc_end_pulse();
#endif
#endif
refcount = 0;
pulsein_tc_index = 0xff;
overflow_count = 0;
}
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) {
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
if (!pin->has_extint) {
mp_raise_RuntimeError(translate("No hardware support on pin"));
}
@ -153,7 +158,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
mp_raise_RuntimeError(translate("EXTINT channel already in use"));
}
self->buffer = (uint16_t *) m_malloc(maxlen * sizeof(uint16_t), false);
self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false);
if (self->buffer == NULL) {
mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t));
}
@ -196,8 +201,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
#ifdef SAMD21
tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 |
TC_CTRLA_PRESCALER_DIV16 |
TC_CTRLA_WAVEGEN_NFRQ;
TC_CTRLA_PRESCALER_DIV16 |
TC_CTRLA_WAVEGEN_NFRQ;
#endif
#ifdef SAM_D5X_E5X
tc_reset(tc);
@ -220,7 +225,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
self->last_overflow = overflow_count;
self->last_count = 0;
set_eic_channel_data(pin->extint_channel, (void*) self);
set_eic_channel_data(pin->extint_channel, (void *)self);
// Check to see if the EIC is enabled and start it up if its not.'
if (eic_get_enable() == 0) {
@ -235,23 +240,23 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
// Set config will enable the EIC.
pulsein_set_config(self, true);
#ifdef SAMD21
#ifdef SAMD21
rtc_start_pulse();
#endif
#endif
}
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
return self->pin == NO_PIN;
}
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
if (common_hal_pulseio_pulsein_deinited(self)) {
return;
}
#ifdef SAMD21
#ifdef SAMD21
rtc_end_pulse();
#endif
#endif
set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
turn_off_eic_channel(self->channel);
reset_pin_number(self->pin);
@ -264,13 +269,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
self->pin = NO_PIN;
}
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) {
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
uint32_t mask = 1 << self->channel;
EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos;
}
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
uint16_t trigger_duration) {
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self,
uint16_t trigger_duration) {
// Make sure we're paused.
common_hal_pulseio_pulsein_pause(self);
@ -297,20 +302,20 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self,
pulsein_set_config(self, true);
}
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) {
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) {
common_hal_mcu_disable_interrupts();
self->start = 0;
self->len = 0;
common_hal_mcu_enable_interrupts();
}
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
if (self->len == 0) {
mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_PulseIn);
}
if (self->errored_too_fast) {
self->errored_too_fast = 0;
mp_raise_RuntimeError(translate("Input taking too long"));
self->errored_too_fast = 0;
mp_raise_RuntimeError(translate("Input taking too long"));
}
common_hal_mcu_disable_interrupts();
uint16_t value = self->buffer[self->start];
@ -320,21 +325,21 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
return value;
}
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) {
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t *self) {
return self->maxlen;
}
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) {
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t *self) {
return self->len;
}
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) {
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) {
uint32_t mask = 1 << self->channel;
return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0;
}
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self,
int16_t index) {
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self,
int16_t index) {
common_hal_mcu_disable_interrupts();
if (index < 0) {
index += self->len;

View File

@ -44,8 +44,8 @@ __attribute__((section(".uninitialized"))) static uint32_t _sleepmem_magicnum;
static int is_sleep_memory_valid(void) {
if ((_sleepmem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK)
== SLEEP_MEMORY_DATA_GUARD) {
return 1;
== SLEEP_MEMORY_DATA_GUARD) {
return 1;
}
return 0;
}
@ -54,36 +54,36 @@ void set_memory_retention(void) {
// set RAM[n].POWER register for RAM retention
// nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5]
// nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1]
for(int block = 0; block <= 7; ++block) {
for (int block = 0; block <= 7; ++block) {
nrf_power_rampower_mask_on(NRF_POWER, block,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
};
#ifdef NRF52840
#ifdef NRF52840
nrf_power_rampower_mask_on(NRF_POWER, 8,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK |
NRF_POWER_RAMPOWER_S2RETENTION_MASK |
NRF_POWER_RAMPOWER_S3RETENTION_MASK |
NRF_POWER_RAMPOWER_S4RETENTION_MASK |
NRF_POWER_RAMPOWER_S5RETENTION_MASK);
#endif
#ifdef NRF52833
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK |
NRF_POWER_RAMPOWER_S2RETENTION_MASK |
NRF_POWER_RAMPOWER_S3RETENTION_MASK |
NRF_POWER_RAMPOWER_S4RETENTION_MASK |
NRF_POWER_RAMPOWER_S5RETENTION_MASK);
#endif
#ifdef NRF52833
nrf_power_rampower_mask_on(NRF_POWER, 8,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
#endif
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
#endif
}
static void initialize_sleep_memory(void) {
memset((uint8_t *)_sleepmem, 0, SLEEP_MEMORY_LENGTH);
sleepmem_wakeup_event = 0;
sleepmem_wakeup_pin = 0;
sleepmem_wakeup_pin = 0;
set_memory_retention();
#ifdef NRF_DEBUG_PRINT
//dbg_dump_RAMreg();
#endif
#ifdef NRF_DEBUG_PRINT
// dbg_dump_RAMreg();
#endif
_sleepmem_magicnum = SLEEP_MEMORY_DATA_GUARD;
}
@ -91,9 +91,9 @@ static void initialize_sleep_memory(void) {
void alarm_sleep_memory_reset(void) {
if (!is_sleep_memory_valid()) {
initialize_sleep_memory();
#ifdef NRF_DEBUG_PRINT
dbg_printf("sleep memory initialized\r\n");
#endif
#ifdef NRF_DEBUG_PRINT
dbg_printf("sleep memory initialized\r\n");
#endif
}
}
@ -101,18 +101,18 @@ uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self
return sizeof(_sleepmem);
}
bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len) {
bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t *values, uint32_t len) {
if (start_index + len > sizeof(_sleepmem)) {
return false;
}
memcpy((uint8_t *) (_sleepmem + start_index), values, len);
memcpy((uint8_t *)(_sleepmem + start_index), values, len);
return true;
}
void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) {
void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t *values, uint32_t len) {
if (start_index + len > sizeof(_sleepmem)) {
return;
}
memcpy(values, (uint8_t *) (_sleepmem + start_index), len);
memcpy(values, (uint8_t *)(_sleepmem + start_index), len);
}

View File

@ -61,7 +61,7 @@ def generate_module_table_header(modules):
# Print header file for all external modules.
mod_defs = []
print("// Automatically generated by makemoduledefs.py.\n")
print("#include \"py/mpconfig.h\"")
print('#include "py/mpconfig.h"')
for module_name, obj_module, enabled_define in modules:
mod_def = "MODULE_DEF_{}".format(module_name.upper())
mod_defs.append(mod_def)

View File

@ -631,6 +631,7 @@ def parse_input_headers(infiles):
return qcfgs, qstrs, i18ns
def escape_bytes(qstr):
if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr):
# qstr is all printable ASCII so render it as-is (for easier debugging)
@ -640,6 +641,7 @@ def escape_bytes(qstr):
qbytes = bytes_cons(qstr, "utf8")
return "".join(("\\x%02x" % b) for b in qbytes)
def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
qbytes = bytes_cons(qstr, "utf8")
qlen = len(qbytes)
@ -715,7 +717,6 @@ def print_qstr_enums(qstrs):
print("QENUM(MP_QSTR_%s)" % (ident,))
if __name__ == "__main__":
import argparse

View File

@ -65,7 +65,6 @@ def get_version_info_from_git():
return git_tag, git_hash, ver
def get_version_info_from_docs_conf():
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "conf.py")) as f:
for line in f:

View File

@ -62,10 +62,10 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k
mp_obj_fun_bc_t *self_fun = (mp_obj_fun_bc_t *)self->fun;
// Determine start of prelude, and extract n_state from it
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
uintptr_t prelude_offset = ((uintptr_t *)self_fun->bytecode)[0];
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
size_t n_state = mp_decode_uint_value(self_fun->bytecode + prelude_offset);
size_t n_exc_stack = 0;
@ -85,10 +85,10 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k
o->code_state.exc_sp = NULL;
// Prepare the generator instance for execution
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
uintptr_t start_offset = ((uintptr_t *)self_fun->bytecode)[1];
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
o->code_state.ip = MICROPY_MAKE_POINTER_CALLABLE((void *)(self_fun->bytecode + start_offset));
return MP_OBJ_FROM_PTR(o);

View File

@ -189,13 +189,13 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_
#if MICROPY_EMIT_THUMB
STATIC void asm_thumb_rewrite_mov(uint8_t *pc, uint16_t val) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
// high part
*(uint16_t *)pc = (*(uint16_t *)pc & 0xfbf0) | (val >> 1 & 0x0400) | (val >> 12);
// low part
*(uint16_t *)(pc + 2) = (*(uint16_t *)(pc + 2) & 0x0f00) | (val << 4 & 0x7000) | (val & 0x00ff);
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
}
#endif

View File

@ -77,13 +77,13 @@ mp_uint_t qstr_compute_hash(const byte *data, size_t len) {
}
const qstr_attr_t mp_qstr_const_attr[] = {
#ifndef NO_QSTR
#ifndef NO_QSTR
#define QDEF(id, hash, len, str) { hash, len },
#define TRANSLATION(id, length, compressed ...)
#include "genhdr/qstrdefs.generated.h"
#include "genhdr/qstrdefs.generated.h"
#undef TRANSLATION
#undef QDEF
#endif
#endif
};
const qstr_pool_t mp_qstr_const_pool = {

View File

@ -49,6 +49,6 @@ bool serial_bytes_available(void);
bool serial_connected(void);
// XXX used in nrf52-sleep debug
int dbg_printf(const char *fmt, ...)__attribute__((format (printf, 1, 2)));
int dbg_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H

View File

@ -65,26 +65,28 @@ extension_by_board = {
"meowbit_v121": UF2,
}
language_allow_list = set([
"ID",
"de_DE",
"en_GB",
"en_US",
"en_x_pirate",
"es",
"fil",
"fr",
"it_IT",
"ja",
"nl",
"pl",
"pt_BR",
"sv",
"zh_Latn_pinyin",
])
language_allow_list = set(
[
"ID",
"de_DE",
"en_GB",
"en_US",
"en_x_pirate",
"es",
"fil",
"fr",
"it_IT",
"ja",
"nl",
"pl",
"pt_BR",
"sv",
"zh_Latn_pinyin",
]
)
def get_languages(list_all = False):
def get_languages(list_all=False):
languages = set()
for f in os.scandir("../locale"):
if f.name.endswith(".po"):

View File

@ -90,8 +90,10 @@ for board in build_boards:
for alias in board_info["aliases"] + [board]:
bin_directory = "../bin/{alias}/{language}".format(alias=alias, language=language)
os.makedirs(bin_directory, exist_ok=True)
final_filename = "adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format(
alias=alias, language=language, version=version, extension=extension
final_filename = (
"adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format(
alias=alias, language=language, version=version, extension=extension
)
)
final_filename = os.path.join(bin_directory, final_filename)
try:

View File

@ -80,15 +80,15 @@ def git_glob_to_regex(pat):
m = m.group(0)
if m == "*":
return "[^/]*"
if m == "**":
return ".*"
if m == "**/":
return "(.*/)?"
if m == "?":
return "[^/]"
if m == ".":
return r"\."
return m
result = [transform(part) for part in re.finditer(r"(\*\*|[*?.]|[^*?.]+)", pat)]
result = [transform(part) for part in re.finditer(r"(\*\*/|[*?.]|[^*?.]+)", pat)]
return "(^" + "".join(result) + "$)"
@ -151,9 +151,7 @@ def fixup_c(filename):
if directive in ("if ", "ifdef ", "ifndef "):
l_next = lines[0]
indent_next = len(re.match(r"( *)", l_next).group(1))
if indent - 4 == indent_next and re.match(
r" +(} else |case )", l_next
):
if indent - 4 == indent_next and re.match(r" +(} else |case )", l_next):
# This #-line (and all associated ones) needs dedenting by 4 spaces.
l = l[4:]
dedent_stack.append(indent - 4)

View File

@ -619,7 +619,6 @@ configuration = standard.ConfigurationDescriptor(
# bit 7 is always 1 and 0-4 are always 0
# Turn off remote wakeup until we handle it in CircuitPython.
bmAttributes=0x80,
)
descriptor_list.insert(0, configuration)

View File

@ -805,7 +805,6 @@ def read_raw_code(f, qstr_win):
)
def read_mpy(filename):
with open(filename, "rb") as f:
header = bytes_cons(f.read(4))
@ -823,7 +822,6 @@ def read_mpy(filename):
return read_raw_code(f, qstr_win)
def dump_mpy(raw_codes):
for rc in raw_codes:
rc.dump()
@ -896,10 +894,10 @@ def freeze_mpy(base_qstrs, raw_codes):
qstr_size = {"metadata": 0, "data": 0}
for _, _, qstr in new:
qbytes = qstrutil.bytes_cons(qstr, "utf8")
print(" {%d, %d}," % (
qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH),
len(qbytes)
))
print(
" {%d, %d},"
% (qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH), len(qbytes))
)
qstr_size["metadata"] += (
config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH
)
@ -919,7 +917,7 @@ def freeze_mpy(base_qstrs, raw_codes):
print(" (qstr_attr_t *)mp_qstr_frozen_const_attr,")
print(" {")
for _, _, qstr in new:
print(" \"%s\"," % qstrutil.escape_bytes(qstr))
print(' "%s",' % qstrutil.escape_bytes(qstr))
print(" },")
print("};")