Merge branch 'adafruit:main' into board-pykey87

This commit is contained in:
Pierre Constantineau 2021-11-15 16:45:15 -06:00 committed by GitHub
commit 4f0fc1eb17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 142 additions and 45 deletions

View File

@ -5392,7 +5392,9 @@ FRESULT f_mkfs (
const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
#if FF_MKFS_FAT32
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
#endif
BYTE fmt, sys, *buf, *pte, part; void *pdrv;
WORD ss; /* Sector size */
DWORD szb_buf, sz_buf, sz_blk, n_clst, pau, sect, nsect, n;
@ -5464,7 +5466,7 @@ FRESULT f_mkfs (
}
}
if (au > 128) LEAVE_MKFS(FR_INVALID_PARAMETER); /* Too large au for FAT/FAT32 */
if (opt & FM_FAT32) { /* FAT32 possible? */
if (FF_MKFS_FAT32 && (opt & FM_FAT32)) { /* FAT32 possible? */
if ((opt & FM_ANY) == FM_FAT32 || !(opt & FM_FAT)) { /* FAT32 only or no-FAT? */
fmt = FS_FAT32; break;
}
@ -5641,6 +5643,7 @@ FRESULT f_mkfs (
do {
pau = au;
/* Pre-determine number of clusters and FAT sub-type */
#if FF_MKFS_FAT32
if (fmt == FS_FAT32) { /* FAT32 volume */
if (pau == 0) { /* au auto-selection */
n = sz_vol / 0x20000; /* Volume size in unit of 128KS */
@ -5651,7 +5654,9 @@ FRESULT f_mkfs (
sz_rsv = 32; /* Number of reserved sectors */
sz_dir = 0; /* No static directory */
if (n_clst <= MAX_FAT16 || n_clst > MAX_FAT32) LEAVE_MKFS(FR_MKFS_ABORTED);
} else { /* FAT volume */
} else
#endif
{ /* FAT volume */
if (pau == 0) { /* au auto-selection */
n = sz_vol / 0x1000; /* Volume size in unit of 4KS */
for (i = 0, pau = 1; cst[i] && cst[i] <= n; i++, pau <<= 1) ; /* Get from table */
@ -5681,12 +5686,14 @@ FRESULT f_mkfs (
/* Determine number of clusters and final check of validity of the FAT sub-type */
if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume */
n_clst = (sz_vol - sz_rsv - sz_fat * n_fats - sz_dir) / pau;
#if FF_MKFS_FAT32
if (fmt == FS_FAT32) {
if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32 */
if (au == 0 && (au = pau / 2) != 0) continue; /* Adjust cluster size and retry */
LEAVE_MKFS(FR_MKFS_ABORTED);
}
}
#endif
if (fmt == FS_FAT16) {
if (n_clst > MAX_FAT16) { /* Too many clusters for FAT16 */
if (au == 0 && (pau * 2) <= 64) {
@ -5720,7 +5727,11 @@ FRESULT f_mkfs (
buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */
st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */
buf[BPB_NumFATs] = (BYTE)n_fats; /* Number of FATs */
#if FF_MKFS_FAT32
st_word(buf + BPB_RootEntCnt, (WORD)((fmt == FS_FAT32) ? 0 : n_rootdir)); /* Number of root directory entries */
#else
st_word(buf + BPB_RootEntCnt, (WORD) n_rootdir); /* Number of root directory entries */
#endif
if (sz_vol < 0x10000) {
st_word(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */
} else {
@ -5730,6 +5741,7 @@ FRESULT f_mkfs (
st_word(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */
st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */
st_dword(buf + BPB_HiddSec, b_vol); /* Volume offset in the physical drive [sector] */
#if FF_MKFS_FAT32
if (fmt == FS_FAT32) {
st_dword(buf + BS_VolID32, GET_FATTIME()); /* VSN */
st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */
@ -5739,7 +5751,9 @@ FRESULT f_mkfs (
buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */
buf[BS_BootSig32] = 0x29; /* Extended boot signature */
mem_cpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
} else {
} else
#endif
{
st_dword(buf + BS_VolID, GET_FATTIME()); /* VSN */
st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */
buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */
@ -5750,6 +5764,7 @@ FRESULT f_mkfs (
if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */
/* Create FSINFO record if needed */
#if FF_MKFS_FAT32
if (fmt == FS_FAT32) {
disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */
mem_set(buf, 0, ss);
@ -5761,16 +5776,20 @@ FRESULT f_mkfs (
disk_write(pdrv, buf, b_vol + 7, 1); /* Write backup FSINFO (VBR + 7) */
disk_write(pdrv, buf, b_vol + 1, 1); /* Write original FSINFO (VBR + 1) */
}
#endif
/* Initialize FAT area */
mem_set(buf, 0, (UINT)szb_buf);
sect = b_fat; /* FAT start sector */
for (i = 0; i < n_fats; i++) { /* Initialize FATs each */
#if FF_MKFS_FAT32
if (fmt == FS_FAT32) {
st_dword(buf + 0, 0xFFFFFFF8); /* Entry 0 */
st_dword(buf + 4, 0xFFFFFFFF); /* Entry 1 */
st_dword(buf + 8, 0x0FFFFFFF); /* Entry 2 (root directory) */
} else {
} else
#endif
{
st_dword(buf + 0, (fmt == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* Entry 0 and 1 */
}
nsect = sz_fat; /* Number of FAT sectors */
@ -5783,7 +5802,11 @@ FRESULT f_mkfs (
}
/* Initialize root directory (fill with zero) */
#if FF_MKFS_FAT32
nsect = (fmt == FS_FAT32) ? pau : sz_dir; /* Number of root directory sectors */
#else
nsect = sz_dir; /* Number of root directory sectors */
#endif
do {
n = (nsect > sz_buf) ? sz_buf : nsect;
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
@ -5795,7 +5818,7 @@ FRESULT f_mkfs (
if (FF_FS_EXFAT && fmt == FS_EXFAT) {
sys = 0x07; /* HPFS/NTFS/exFAT */
} else {
if (fmt == FS_FAT32) {
if (FF_MKFS_FAT32 && fmt == FS_FAT32) {
sys = 0x0C; /* FAT32X */
} else {
if (sz_vol >= 0x10000) {

View File

@ -72,6 +72,12 @@
#define FF_USE_MKFS 1
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
#ifdef MICROPY_FF_MKFS_FAT32
#define FF_MKFS_FAT32 MICROPY_FF_MKFS_FAT32
#else
#define FF_MKFS_FAT32 0
#endif
/* This option switches off FAT32 support in f_mkfs() */
#define FF_USE_FASTSEEK 1
/* This option switches fast seek function. (0:Disable or 1:Enable) */

View File

@ -9,5 +9,3 @@ CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -11,4 +11,3 @@ LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -9,5 +9,3 @@ CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -88,7 +88,7 @@ endif
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
CFLAGS += $(OPTIMIZATION_FLAGS)
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT)
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -Werror=missing-prototypes
# TODO: check this
CFLAGS += -D__START=main -DFOMU

View File

@ -28,6 +28,7 @@
#include "supervisor/filesystem.h"
#include "supervisor/usb.h"
#include "supervisor/shared/stack.h"
#include "supervisor/port.h"
void port_background_task(void) {
}

View File

@ -29,6 +29,7 @@
#include "py/runtime.h"
#include "common-hal/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/ResetReason.h"
#include "supervisor/shared/translate.h"

View File

@ -30,6 +30,8 @@
#include "py/objtuple.h"
#include "py/qstr.h"
#include "shared-bindings/os/__init__.h"
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
@ -56,6 +58,6 @@ mp_obj_t common_hal_os_uname(void) {
return (mp_obj_t)&os_uname_info_obj;
}
bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) {
return false;
}

View File

@ -31,6 +31,7 @@
#include "py/mphal.h"
#include "py/mpstate.h"
#include "py/gc.h"
#include "supervisor/cpu.h"
#include "supervisor/usb.h"
#include "csr.h"
@ -54,6 +55,7 @@ extern void SysTick_Handler(void);
// be prematurely enabled by interrupt handlers that enable and disable interrupts.
extern volatile uint32_t nesting_count;
void isr(void);
__attribute__((section(".ramtext")))
void isr(void) {
uint8_t irqs = irq_pending() & irq_getmask();

View File

@ -38,6 +38,7 @@
// crystals.
volatile uint64_t raw_ticks = 0;
volatile int subsecond = 0;
void SysTick_Handler(void);
__attribute__((section(".ramtext")))
void SysTick_Handler(void) {
timer0_ev_pending_write(1);

View File

@ -92,7 +92,7 @@ else
#CFLAGS += -flto -flto-partition=none
endif
CFLAGS += $(INC) -ggdb -Wall -Wno-cast-align -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT)
CFLAGS += $(INC) -ggdb -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) -Werror=missing-prototypes
# TODO: add these when -Werror is applied
# Disable some warnings, as do most ports. NXP SDK causes undef, tinyusb causes cast-align
@ -148,7 +148,7 @@ SRC_SDK := \
system_$(CHIP_FAMILY).c \
SRC_SDK := $(addprefix sdk/devices/$(CHIP_FAMILY)/, $(SRC_SDK))
$(addprefix $(BUILD)/, $(SRC_SDK:.c=.o)): CFLAGS += -Wno-undef
$(addprefix $(BUILD)/, $(SRC_SDK:.c=.o)): CFLAGS += -Wno-undef -Wno-missing-prototypes -Wno-cast-align
SRC_C += \
background.c \

View File

@ -26,6 +26,7 @@
*/
#include "common-hal/analogio/AnalogIn.h"
#include "shared-bindings/analogio/AnalogIn.h"
#include "shared-bindings/microcontroller/Pin.h"
#include <string.h>

View File

@ -41,4 +41,6 @@ typedef struct {
const mcu_periph_obj_t *sda;
} busio_i2c_obj_t;
void i2c_reset(void);
#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_BUSIO_I2C_H

View File

@ -65,7 +65,7 @@ static void config_periph_pin(const mcu_periph_obj_t *periph) {
| IOMUXC_SW_PAD_CTL_PAD_SRE(0));
}
void LPUART_UserCallback(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *user_data) {
STATIC void LPUART_UserCallback(LPUART_Type *base, lpuart_handle_t *handle, status_t status, void *user_data) {
busio_uart_obj_t *self = (busio_uart_obj_t *)user_data;
if (status == kStatus_LPUART_RxIdle) {

View File

@ -51,4 +51,5 @@ typedef struct {
const mcu_periph_obj_t *rts;
} busio_uart_obj_t;
void uart_reset(void);
#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_BUSIO_UART_H

View File

@ -40,7 +40,7 @@
#define IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_ALT5 5U
void pin_config(const mcu_pin_obj_t *pin, bool open_drain, digitalio_pull_t pull) {
STATIC void pin_config(const mcu_pin_obj_t *pin, bool open_drain, digitalio_pull_t pull) {
IOMUXC_SetPinConfig(0, 0, 0, 0, pin->cfg_reg,
IOMUXC_SW_PAD_CTL_PAD_HYS(1)
| IOMUXC_SW_PAD_CTL_PAD_PUS((pull == PULL_UP) ? 2 : 0)

View File

@ -28,6 +28,7 @@
#include <math.h>
#include "common-hal/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "shared-bindings/microcontroller/ResetReason.h"
#include "fsl_tempmon.h"

View File

@ -31,6 +31,8 @@
#include "py/objtuple.h"
#include "py/qstr.h"
#include "shared-bindings/os/__init__.h"
#include "fsl_trng.h"
STATIC const qstr os_uname_info_fields[] = {
@ -58,7 +60,7 @@ mp_obj_t common_hal_os_uname(void) {
return (mp_obj_t)&os_uname_info_obj;
}
bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) {
trng_config_t trngConfig;
TRNG_GetDefaultConfig(&trngConfig);

View File

@ -31,6 +31,8 @@
#include "py/runtime.h"
#include "shared/timeutils/timeutils.h"
#include "shared-bindings/rtc/__init__.h"
#include "shared-bindings/rtc/RTC.h"
#include "common-hal/rtc/RTC.h"
#include "supervisor/shared/translate.h"
#include "fsl_snvs_hp.h"

View File

@ -25,6 +25,7 @@
* THE SOFTWARE.
*/
#include "py/mphal.h"
#include "py/mpstate.h"
#include "py/smallint.h"

View File

@ -35,6 +35,8 @@
#include "fsl_clock.h"
#include "fsl_iomuxc.h"
#include "clocks.h"
#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */
#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32k frequency in Hz */

View File

@ -36,6 +36,8 @@
#include "fsl_clock.h"
#include "fsl_iomuxc.h"
#include "clocks.h"
// These values are pulled from the SDK's devices/MIMXRT1021/project_template/clock_config.* files.
#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */

View File

@ -35,6 +35,8 @@
#include "fsl_clock.h"
#include "fsl_iomuxc.h"
#include "clocks.h"
#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */
#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32k frequency in Hz */
#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 600000000U /*!< Core clock frequency: 600000000Hz */

View File

@ -10,9 +10,10 @@
#include "fsl_flexspi.h"
#include "internal_flash.h"
#include "boards/flash_config.h"
#include "supervisor/internal_flash.h"
#include "supervisor/linker.h"
status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uint32_t baseAddr)
STATIC status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uint32_t baseAddr)
{
flexspi_transfer_t flashXfer;
status_t status;
@ -29,7 +30,7 @@ status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uint32_t b
return status;
}
status_t PLACE_IN_ITCM(flexspi_nor_wait_bus_busy)(FLEXSPI_Type * base)
STATIC status_t PLACE_IN_ITCM(flexspi_nor_wait_bus_busy)(FLEXSPI_Type * base)
{
/* Wait status ready. */
bool isBusy;

View File

@ -52,10 +52,6 @@ extern uint32_t __fatfs_flash_length[];
uint8_t _flash_cache[SECTOR_SIZE] __attribute__((aligned(4)));
uint32_t _flash_page_addr = NO_CACHE;
extern status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address);
extern status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t dstAddr, const uint32_t *src);
extern status_t flexspi_nor_enable_quad_mode(FLEXSPI_Type *base);
void PLACE_IN_ITCM(supervisor_flash_init)(void) {
// Update the LUT to make sure all entries are available.
FLEXSPI_UpdateLUT(FLEXSPI, 0, (const uint32_t *)&qspiflash_config.memConfig.lookupTable, 64);

View File

@ -30,6 +30,7 @@
#include <stdint.h>
#include "py/mpconfig.h"
#include "fsl_common.h"
#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)
@ -41,4 +42,9 @@
#define ROM_INDEX_PAGEPROGRAM 9
#define ROM_INDEX_READSTATUSREG 1
extern status_t flexspi_nor_flash_erase_sector(FLEXSPI_Type *base, uint32_t address);
extern status_t flexspi_nor_flash_page_program(FLEXSPI_Type *base, uint32_t dstAddr, const uint32_t *src);
extern status_t flexspi_nor_enable_quad_mode(FLEXSPI_Type *base);
#endif // MICROPY_INCLUDED_MIMXRT10XX_INTERNAL_FLASH_H

View File

@ -104,6 +104,7 @@ extern uint32_t _ld_itcm_flash_copy;
extern void main(void);
// This replaces the Reset_Handler in startup_*.S and SystemInit in system_*.c.
void Reset_Handler(void);
__attribute__((used, naked)) void Reset_Handler(void) {
__disable_irq();
SCB->VTOR = (uint32_t)&__isr_vector;
@ -358,6 +359,8 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
return ticks / 32;
}
void SNVS_HP_WRAPPER_IRQHandler(void);
__attribute__((used))
void SNVS_HP_WRAPPER_IRQHandler(void) {
if ((SNVS->HPSR & SNVS_HPSR_PI_MASK) != 0) {
supervisor_tick();
@ -415,6 +418,7 @@ void port_idle_until_interrupt(void) {
/**
* \brief Default interrupt handler for unused IRQs.
*/
void MemManage_Handler(void);
__attribute__((used)) void MemManage_Handler(void) {
reset_into_safe_mode(MEM_MANAGE);
while (true) {
@ -425,6 +429,7 @@ __attribute__((used)) void MemManage_Handler(void) {
/**
* \brief Default interrupt handler for unused IRQs.
*/
void BusFault_Handler(void);
__attribute__((used)) void BusFault_Handler(void) {
reset_into_safe_mode(MEM_MANAGE);
while (true) {
@ -435,6 +440,7 @@ __attribute__((used)) void BusFault_Handler(void) {
/**
* \brief Default interrupt handler for unused IRQs.
*/
void UsageFault_Handler(void);
__attribute__((used)) void UsageFault_Handler(void) {
reset_into_safe_mode(MEM_MANAGE);
while (true) {
@ -445,6 +451,7 @@ __attribute__((used)) void UsageFault_Handler(void) {
/**
* \brief Default interrupt handler for unused IRQs.
*/
void HardFault_Handler(void);
__attribute__((used)) void HardFault_Handler(void) {
reset_into_safe_mode(HARD_CRASH);
while (true) {

View File

@ -52,6 +52,7 @@ void init_usb_hardware(void) {
usb_phy->TX = phytx;
}
void USB_OTG1_IRQHandler(void);
void USB_OTG1_IRQHandler(void) {
usb_irq_handler();
}

View File

@ -59,6 +59,7 @@
#define MICROPY_PY_URE_SUB (1)
#define MICROPY_VFS_POSIX (1)
#define MICROPY_FATFS_USE_LABEL (1)
#define MICROPY_FF_MKFS_FAT32 (1)
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)

View File

@ -31,18 +31,21 @@ SRC_BITMAP := \
$(patsubst ../../%,%,$(wildcard ../../shared-bindings/gifio/*.c ../../shared-module/gifio/*.c)) \
shared/runtime/context_manager_helpers.c \
displayio_min.c \
shared-bindings/bitmaptools/__init__.c \
shared-bindings/displayio/Bitmap.c \
shared-bindings/rainbowio/__init__.c \
shared-bindings/util.c \
shared-module/bitmaptools/__init__.c \
shared-module/displayio/area.c \
shared-module/displayio/Bitmap.c \
shared-module/displayio/ColorConverter.c \
shared-bindings/bitmaptools/__init__.c \
shared-module/bitmaptools/__init__.c \
shared-bindings/util.c \
shared-module/displayio/ColorConverter.c \
shared-module/rainbowio/__init__.c \
$(info $(SRC_BITMAP))
SRC_C += $(SRC_BITMAP)
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_UNIX=1 -DCIRCUITPY_BITMAPTOOLS=1
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_UNIX=1 -DCIRCUITPY_BITMAPTOOLS=1 -DCIRCUITPY_RAINBOWIO=1
SRC_C += coverage.c
SRC_CXX += coveragecpp.cpp

View File

@ -54,7 +54,7 @@
//| Pin used to latch parallel data going into the shift register.
//| :param bool value_to_latch: Pin state to latch data being read.
//| ``True`` if the data is latched when ``latch`` goes high
//| ``False`` if the data is latched when ``latch goes low.
//| ``False`` if the data is latched when ``latch`` goes low.
//| The default is ``True``, which is how the 74HC165 operates. The CD4021 latch is the opposite.
//| Once the data is latched, it will be shifted out by toggling the clock pin.
//| :param int key_count: number of data lines to clock in

View File

@ -37,7 +37,8 @@
//| ...
//|
STATIC mp_obj_t rainbowio_colorwheel(mp_obj_t n) {
return MP_OBJ_NEW_SMALL_INT(colorwheel(mp_obj_is_small_int(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_get_float(n)));
mp_float_t f = mp_obj_get_float(n);
return MP_OBJ_NEW_SMALL_INT(colorwheel(f));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rainbowio_colorwheel_obj, rainbowio_colorwheel);

View File

@ -27,7 +27,8 @@
#ifndef CP_SHARED_BINDINGS_RAINBOWIO_INIT_H
#define CP_SHARED_BINDINGS_RAINBOWIO_INIT_H
#include <stdint.h>
#include "py/misc.h"
const int32_t colorwheel(float pos);
int32_t colorwheel(mp_float_t pos);
#endif // CP_SHARED_BINDINGS_RAINBOWIO_INIT_H

View File

@ -26,17 +26,21 @@
#include "shared-bindings/rainbowio/__init__.h"
const int32_t colorwheel(float pos) {
if (pos > 255) {
pos = pos - ((uint32_t)(pos / 256) * 256);
}
int32_t colorwheel(mp_float_t pos) {
pos = pos - ((uint32_t)(pos / 256) * 256);
int shift1, shift2;
if (pos < 85) {
return (uint8_t)(255 - (pos * 3)) << 16 | (uint8_t)(pos * 3) << 8;
shift1 = 8;
shift2 = 16;
} else if (pos < 170) {
pos -= 85;
return (uint8_t)(255 - (pos * 3)) << 8 | (uint8_t)(pos * 3);
shift1 = 0;
shift2 = 8;
} else {
pos -= 170;
return (uint8_t)(pos * 3) << 16 | (uint8_t)(255 - (pos * 3));
shift1 = 16;
shift2 = 0;
}
int p = (int)(pos * 3);
return (p << shift1) | ((255 - p) << shift2);
}

View File

@ -1,2 +0,0 @@
import digitalio
import board

View File

@ -0,0 +1,6 @@
import rainbowio
for i in range(0, 256, 15):
print("{:3} {:06x} {:06x}".format(i, rainbowio.colorwheel(i), rainbowio.colorwheel(float(i))))
for i in range(256, 1024, 128):
print("{:3} {:06x}".format(i, rainbowio.colorwheel(i)))

View File

@ -0,0 +1,24 @@
0 ff0000 ff0000
15 d22d00 d22d00
30 a55a00 a55a00
45 788700 788700
60 4bb400 4bb400
75 1ee100 1ee100
90 00f00f 00f00f
105 00c33c 00c33c
120 009669 009669
135 006996 006996
150 003cc3 003cc3
165 000ff0 000ff0
180 1e00e1 1e00e1
195 4b00b4 4b00b4
210 780087 780087
225 a5005a a5005a
240 d2002d d2002d
255 ff0000 ff0000
256 ff0000
384 007e81
512 ff0000
640 007e81
768 ff0000
896 007e81

View File

@ -1 +1 @@
../tools/cpboard.py
../tools/cpboard.py

View File

@ -819,6 +819,7 @@ the last matching regex is used:
if args.test_dirs is None:
test_dirs = (
"basics",
"circuitpython",
"micropython",
"misc",
"extmod",

View File

@ -34,11 +34,11 @@ binascii bitmaptools btree cexample
cmath collections cppexample displayio
errno ffi framebuf gc
gifio hashlib json math
qrio re sys termios
ubinascii uctypes uerrno uheapq
uio ujson ulab uos
urandom ure uselect ustruct
utime utimeq uzlib
qrio rainbowio re sys
termios ubinascii uctypes uerrno
uheapq uio ujson ulab
uos urandom ure uselect
ustruct utime utimeq uzlib
ime
utime utimeq