Merge branch 'main' into disable_network

This commit is contained in:
Scott Shawcroft 2020-07-20 16:28:22 -07:00 committed by GitHub
commit 0c6935e336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 172 additions and 30 deletions

@ -1 +1 @@
Subproject commit 0d2c083a2fb57a1562d4806775f45273abbfbfae
Subproject commit 9596a5904ed757e6fbffcf03e7aa77ae9ecf5223

View File

@ -10,9 +10,6 @@ INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
# TODO: Turn off analogio for now for space reasons, but restore it
# when frozen module gets smaller.
CIRCUITPY_ANALOGIO = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_AUDIOMP3 = 0
@ -32,6 +29,7 @@ CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_ANALOGIO = 1
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_AUDIOIO = 1
CIRCUITPY_DISPLAYIO = 1

View File

@ -30,3 +30,7 @@ CIRCUITPY_PS2IO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_RTC = 0
# Enable board-specific modules
USER_C_MODULES = boards/winterbloom_big_honking_button/usermods
CFLAGS += -DMODULE_BHB_ENABLED=1

View File

@ -0,0 +1,120 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "samd/pins.h"
#include "sam.h"
STATIC mp_obj_t _bhb_read_adc(void);
STATIC mp_obj_t _bhb_init_adc(void) {
claim_pin(&pin_PB08);
common_hal_never_reset_pin(&pin_PB08);
/* Enable the APB clock for the ADC. */
PM->APBCMASK.reg |= PM_APBCMASK_ADC;
/* Enable GCLK0 for the ADC */
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |
GCLK_CLKCTRL_GEN_GCLK0 |
GCLK_CLKCTRL_ID_ADC;
/* Wait for bus synchronization. */
while (GCLK->STATUS.bit.SYNCBUSY) {};
uint32_t bias = (*((uint32_t *) ADC_FUSES_BIASCAL_ADDR) & ADC_FUSES_BIASCAL_Msk) >> ADC_FUSES_BIASCAL_Pos;
uint32_t linearity = (*((uint32_t *) ADC_FUSES_LINEARITY_0_ADDR) & ADC_FUSES_LINEARITY_0_Msk) >> ADC_FUSES_LINEARITY_0_Pos;
linearity |= ((*((uint32_t *) ADC_FUSES_LINEARITY_1_ADDR) & ADC_FUSES_LINEARITY_1_Msk) >> ADC_FUSES_LINEARITY_1_Pos) << 5;
/* Wait for bus synchronization. */
while (ADC->STATUS.bit.SYNCBUSY) {};
/* Write the calibration data. */
ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);
/* Use the internal VCC reference. This is 1/2 of what's on VCCA.
since VCCA is 3.3v, this is 1.65v.
*/
ADC->REFCTRL.reg = ADC_REFCTRL_REFSEL_INTVCC1;
/* Capture 64 samples. */
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_64 | ADC_AVGCTRL_ADJRES(4);
/* Set the clock prescaler to 32, which is the same as the CircuitPython default.
Set the resolution to 16 for averaging
*/
ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV32 |
ADC_CTRLB_RESSEL_16BIT;
/* Configure the input parameters.
- GAIN_DIV2 means that the input voltage is halved. This is important
because the voltage reference is 1/2 of VCCA. So if you want to
measure 0-3.3v, you need to halve the input as well.
- MUXNEG_GND means that the ADC should compare the input value to GND.
- MUXPOS_PIN3 means that the ADC should read from AIN2, or PB08.
*/
ADC->INPUTCTRL.reg = ADC_INPUTCTRL_GAIN_DIV2 |
ADC_INPUTCTRL_MUXNEG_GND |
ADC_INPUTCTRL_MUXPOS_PIN2;
/* Set PB08 as an input pin. */
PORT->Group[1].DIRCLR.reg = PORT_PB08;
/* Enable the peripheral multiplexer for PB08. */
PORT->Group[1].PINCFG[8].reg |= PORT_PINCFG_PMUXEN;
/* Set PB08 to function B which is analog input. */
PORT->Group[1].PMUX[4].reg |= PORT_PMUX_PMUXE_B;
/* Wait for bus synchronization. */
while (ADC->STATUS.bit.SYNCBUSY) {};
/* Enable the ADC. */
ADC->CTRLA.bit.ENABLE = true;
/* Make one read and throw it away, as per the datasheet. */
_bhb_read_adc();
return mp_const_none;
}
STATIC mp_obj_t _bhb_read_adc(void) {
/* Wait for bus synchronization. */
while (ADC->STATUS.bit.SYNCBUSY) {};
/* Start the ADC using a software trigger. */
ADC->SWTRIG.bit.START = true;
/* Wait for the result ready flag to be set. */
while (ADC->INTFLAG.bit.RESRDY == 0);
/* Clear the flag. */
ADC->INTFLAG.reg = ADC_INTFLAG_RESRDY;
/* Read the value. */
uint32_t result = ADC->RESULT.reg;
return MP_OBJ_NEW_SMALL_INT(result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(_bhb_init_adc_obj, _bhb_init_adc);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(_bhb_read_adc_obj, _bhb_read_adc);
STATIC const mp_rom_map_elem_t _bhb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__bhb) },
{ MP_ROM_QSTR(MP_QSTR_init_adc), MP_ROM_PTR(&_bhb_init_adc_obj) },
{ MP_ROM_QSTR(MP_QSTR_read_adc), MP_ROM_PTR(&_bhb_read_adc_obj) },
};
STATIC MP_DEFINE_CONST_DICT(_bhb_module_globals, _bhb_module_globals_table);
const mp_obj_module_t _bhb_user_cmodule = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&_bhb_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR__bhb, _bhb_user_cmodule, MODULE_BHB_ENABLED);

View File

@ -0,0 +1,6 @@
USERMODULES_DIR := $(USERMOD_DIR)
# Add all C files to SRC_USERMOD.
SRC_USERMOD += $(USERMODULES_DIR)/bhb.c
CFLAGS_USERMOD += -I$(USERMODULES_DIR)

View File

@ -49,20 +49,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
//|
STATIC mp_obj_t vectorio_polygon_obj_get_points(mp_obj_t self_in) {
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t list = mp_obj_new_list(0, NULL);
size_t len = 0;
mp_obj_t *items;
mp_obj_list_get(common_hal_vectorio_polygon_get_points(self), &len, &items);
for (size_t i = 0; i < len; i += 2) {
mp_obj_t tuple[] = { items[i], items[i+1] };
mp_obj_list_append(
list,
mp_obj_new_tuple(2, tuple)
);
}
return list;
return common_hal_vectorio_polygon_get_points(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_polygon_get_points_obj, vectorio_polygon_obj_get_points);

View File

@ -190,9 +190,7 @@ void reset_displays(void) {
common_hal_displayio_epaperdisplay_show(display, NULL);
#if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
display->auto_refresh = true;
common_hal_framebufferio_framebufferdisplay_show(display, NULL);
framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
#endif
}
}

View File

@ -318,3 +318,8 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp
gc_collect_ptr(self->framebuffer);
displayio_display_core_collect_ptrs(&self->core);
}
void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self) {
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, true);
common_hal_framebufferio_framebufferdisplay_show(self, NULL);
}

View File

@ -55,6 +55,7 @@ typedef struct {
void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t* self);
void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
void reset_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self);
void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t* self);

View File

@ -20,7 +20,7 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
size_t len = 0;
mp_obj_t *items;
mp_obj_list_get(points_tuple_list, &len, &items);
VECTORIO_POLYGON_DEBUG("polygon_points_list len: %d\n", len);
VECTORIO_POLYGON_DEBUG(" self.len: %d, len: %d, ", self->len, len);
if ( len < 3 ) {
mp_raise_TypeError_varg(translate("Polygon needs at least 3 points"));
@ -28,9 +28,11 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
if ( self->len < 2*len ) {
if ( self->points_list != NULL ) {
VECTORIO_POLYGON_DEBUG("free(%d), ", sizeof(self->points_list));
gc_free( self->points_list );
}
self->points_list = gc_alloc( 2 * len * sizeof(int), false, false );
VECTORIO_POLYGON_DEBUG("alloc(%p, %d)", self->points_list, 2 * len * sizeof(int));
}
self->len = 2*len;
@ -56,22 +58,35 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list) {
VECTORIO_POLYGON_DEBUG("%p polygon_construct\n", self);
VECTORIO_POLYGON_DEBUG("%p polygon_construct: ", self);
self->points_list = NULL;
self->len = 0;
self->on_dirty.obj = NULL;
_clobber_points_list( self, points_list );
VECTORIO_POLYGON_DEBUG("\n");
}
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self) {
return self->points_list;
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_get_points {len: %d, points_list: %p}\n", self, self->len, self->points_list);
mp_obj_t list = mp_obj_new_list(self->len/2, NULL);
for (size_t i = 0; i < self->len; i += 2) {
mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i+1]) };
mp_obj_list_append(
list,
mp_obj_new_tuple(2, tuple)
);
}
return list;
}
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list) {
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_set_points: ", self);
_clobber_points_list( self, points_list );
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
VECTORIO_POLYGON_DEBUG("\n");
}
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {

View File

@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
#include <string.h>
#include "py/gc.h"
#include "py/mpconfig.h"
#include "supervisor/background_callback.h"
@ -101,6 +103,12 @@ void background_callback_end_critical_section() {
void background_callback_reset() {
CALLBACK_CRITICAL_BEGIN;
background_callback_t *cb = (background_callback_t*)callback_head;
while(cb) {
background_callback_t *next = cb->next;
memset(cb, 0, sizeof(*cb));
cb = next;
}
callback_head = NULL;
callback_tail = NULL;
in_background_callback = false;

View File

@ -66,7 +66,7 @@
static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
static background_callback_t callback;
static background_callback_t tick_callback;
volatile uint64_t last_finished_tick = 0;
@ -119,7 +119,7 @@ void supervisor_tick(void) {
#endif
}
#endif
background_callback_add(&callback, supervisor_background_tasks, NULL);
background_callback_add(&tick_callback, supervisor_background_tasks, NULL);
}
uint64_t supervisor_ticks_ms64() {

View File

@ -64,8 +64,8 @@ void usb_init(void) {
tusb_init();
#if MICROPY_KBD_EXCEPTION
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received
// This callback always got invoked regardless of mp_interrupt_char value since we only set it once here
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received
// This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here
tud_cdc_set_wanted_char(CHAR_CTRL_C);
#endif
@ -83,14 +83,14 @@ void usb_background(void) {
}
}
static background_callback_t callback;
static background_callback_t usb_callback;
static void usb_background_do(void* unused) {
usb_background();
}
void usb_irq_handler(void) {
tud_int_handler(0);
background_callback_add(&callback, usb_background_do, NULL);
background_callback_add(&usb_callback, usb_background_do, NULL);
}
//--------------------------------------------------------------------+