Adding countio to rp2040

This commit is contained in:
gamblor21 2021-02-23 19:26:11 -06:00
parent acbf66dacc
commit 379f454ce6
6 changed files with 250 additions and 7 deletions

View File

@ -339,6 +339,10 @@ msgstr ""
msgid "All event channels in use" msgid "All event channels in use"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "All state machines in use"
msgstr ""
#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c #: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c
msgid "All sync event channels in use" msgid "All sync event channels in use"
msgstr "" msgstr ""
@ -387,6 +391,7 @@ msgstr ""
#: ports/cxd56/common-hal/analogio/AnalogOut.c #: ports/cxd56/common-hal/analogio/AnalogOut.c
#: ports/mimxrt10xx/common-hal/analogio/AnalogOut.c #: ports/mimxrt10xx/common-hal/analogio/AnalogOut.c
#: ports/nrf/common-hal/analogio/AnalogOut.c #: ports/nrf/common-hal/analogio/AnalogOut.c
#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
msgid "AnalogOut functionality not supported" msgid "AnalogOut functionality not supported"
msgstr "" msgstr ""
@ -533,6 +538,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c #: ports/atmel-samd/common-hal/displayio/ParallelBus.c
#: ports/esp32s2/common-hal/displayio/ParallelBus.c #: ports/esp32s2/common-hal/displayio/ParallelBus.c
#: ports/nrf/common-hal/displayio/ParallelBus.c #: ports/nrf/common-hal/displayio/ParallelBus.c
#: ports/raspberrypi/common-hal/displayio/ParallelBus.c
#, c-format #, c-format
msgid "Bus pin %d is already in use" msgid "Bus pin %d is already in use"
msgstr "" msgstr ""
@ -586,6 +592,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c #: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c
#: ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c #: ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c
#: ports/nrf/common-hal/digitalio/DigitalInOut.c #: ports/nrf/common-hal/digitalio/DigitalInOut.c
#: ports/raspberrypi/common-hal/digitalio/DigitalInOut.c
msgid "Cannot get pull while in output mode" msgid "Cannot get pull while in output mode"
msgstr "" msgstr ""
@ -863,7 +870,8 @@ msgstr ""
msgid "Error: Failure to bind" msgid "Error: Failure to bind"
msgstr "" msgstr ""
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c #: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
#: shared-bindings/busio/SPI.c shared-bindings/microcontroller/Pin.c #: shared-bindings/busio/SPI.c shared-bindings/microcontroller/Pin.c
#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/neopixel_write/__init__.c
#: shared-bindings/terminalio/Terminal.c #: shared-bindings/terminalio/Terminal.c
@ -1045,6 +1053,10 @@ msgstr ""
msgid "I2C Init Error" msgid "I2C Init Error"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/busio/I2C.c
msgid "I2C peripheral in use"
msgstr ""
#: shared-bindings/audiobusio/I2SOut.c #: shared-bindings/audiobusio/I2SOut.c
msgid "I2SOut not available" msgid "I2SOut not available"
msgstr "" msgstr ""
@ -1068,6 +1080,10 @@ msgstr ""
msgid "Incorrect buffer size" msgid "Incorrect buffer size"
msgstr "" msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Init program size invalid"
msgstr ""
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "Initialization failed due to lack of memory" msgid "Initialization failed due to lack of memory"
msgstr "" msgstr ""
@ -1080,6 +1096,31 @@ msgstr ""
msgid "Input/output error" msgid "Input/output error"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Instruction %d jumps on pin"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Instruction %d shifts in more bits than pin count"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Instruction %d shifts out more bits than pin count"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Instruction %d uses extra pin"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Instruction %d waits on input outside of count"
msgstr ""
#: ports/nrf/common-hal/_bleio/__init__.c #: ports/nrf/common-hal/_bleio/__init__.c
msgid "Insufficient authentication" msgid "Insufficient authentication"
msgstr "" msgstr ""
@ -1131,7 +1172,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/atmel-samd/common-hal/pwmio/PWMOut.c
#: ports/cxd56/common-hal/pwmio/PWMOut.c ports/nrf/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c ports/nrf/common-hal/pwmio/PWMOut.c
#: shared-bindings/pwmio/PWMOut.c #: ports/raspberrypi/common-hal/pwmio/PWMOut.c shared-bindings/pwmio/PWMOut.c
msgid "Invalid PWM frequency" msgid "Invalid PWM frequency"
msgstr "" msgstr ""
@ -1225,6 +1266,8 @@ msgstr ""
#: ports/mimxrt10xx/common-hal/busio/I2C.c #: ports/mimxrt10xx/common-hal/busio/I2C.c
#: ports/mimxrt10xx/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/I2C.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/I2C.c
#: ports/raspberrypi/common-hal/busio/I2C.c
#: ports/raspberrypi/common-hal/busio/SPI.c
msgid "Invalid pins" msgid "Invalid pins"
msgstr "" msgstr ""
@ -1346,6 +1389,36 @@ msgstr ""
msgid "Missing MISO or MOSI Pin" msgid "Missing MISO or MOSI Pin"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_in_pin. Instruction %d reads pin(s)"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_in_pin. Instruction %d shifts in from pin(s)"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_in_pin. Instruction %d waits based on pin"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_out_pin. Instruction %d shifts out to pin(s)"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_out_pin. Instruction %d writes pin(s)"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#, c-format
msgid "Missing first_set_pin. Instruction %d sets pin(s)"
msgstr ""
#: shared-bindings/displayio/Group.c #: shared-bindings/displayio/Group.c
msgid "Must be a %q subclass." msgid "Must be a %q subclass."
msgstr "" msgstr ""
@ -1399,14 +1472,14 @@ msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/UART.c
#: ports/esp32s2/common-hal/busio/UART.c #: ports/esp32s2/common-hal/busio/UART.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
#: ports/stm/common-hal/busio/UART.c #: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "No RX pin" msgid "No RX pin"
msgstr "" msgstr ""
#: ports/atmel-samd/common-hal/busio/UART.c #: ports/atmel-samd/common-hal/busio/UART.c
#: ports/esp32s2/common-hal/busio/UART.c #: ports/esp32s2/common-hal/busio/UART.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/nrf/common-hal/busio/UART.c
#: ports/stm/common-hal/busio/UART.c #: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "No TX pin" msgid "No TX pin"
msgstr "" msgstr ""
@ -1463,6 +1536,10 @@ msgstr ""
msgid "No network with that ssid" msgid "No network with that ssid"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "No out in program"
msgstr ""
#: shared-module/touchio/TouchIn.c #: shared-module/touchio/TouchIn.c
msgid "No pulldown on pin; 1Mohm recommended" msgid "No pulldown on pin; 1Mohm recommended"
msgstr "" msgstr ""
@ -1518,6 +1595,10 @@ msgstr ""
msgid "Only 8 or 16 bit mono with " msgid "Only 8 or 16 bit mono with "
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Only IN/OUT of up to 8 supported"
msgstr ""
#: ports/esp32s2/common-hal/wifi/__init__.c #: ports/esp32s2/common-hal/wifi/__init__.c
msgid "Only IPv4 addresses supported" msgid "Only IPv4 addresses supported"
msgstr "" msgstr ""
@ -1602,11 +1683,20 @@ msgstr ""
msgid "Permission denied" msgid "Permission denied"
msgstr "" msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Pin count must be at least 1"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Pin count too large"
msgstr ""
#: ports/atmel-samd/common-hal/analogio/AnalogIn.c #: ports/atmel-samd/common-hal/analogio/AnalogIn.c
#: ports/cxd56/common-hal/analogio/AnalogIn.c #: ports/cxd56/common-hal/analogio/AnalogIn.c
#: ports/esp32s2/common-hal/analogio/AnalogIn.c #: ports/esp32s2/common-hal/analogio/AnalogIn.c
#: ports/mimxrt10xx/common-hal/analogio/AnalogIn.c #: ports/mimxrt10xx/common-hal/analogio/AnalogIn.c
#: ports/nrf/common-hal/analogio/AnalogIn.c #: ports/nrf/common-hal/analogio/AnalogIn.c
#: ports/raspberrypi/common-hal/analogio/AnalogIn.c
#: ports/stm/common-hal/analogio/AnalogIn.c #: ports/stm/common-hal/analogio/AnalogIn.c
msgid "Pin does not have ADC capabilities" msgid "Pin does not have ADC capabilities"
msgstr "" msgstr ""
@ -1616,6 +1706,10 @@ msgstr ""
msgid "Pin is input only" msgid "Pin is input only"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/countio/Counter.c
msgid "Pin must be on PWM Channel B"
msgstr ""
#: ports/atmel-samd/common-hal/countio/Counter.c #: ports/atmel-samd/common-hal/countio/Counter.c
msgid "Pin must support hardware interrupts" msgid "Pin must support hardware interrupts"
msgstr "" msgstr ""
@ -1667,6 +1761,26 @@ msgstr ""
msgid "Pretending to deep sleep until alarm, CTRL-C or file write.\n" msgid "Pretending to deep sleep until alarm, CTRL-C or file write.\n"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Program does IN without loading ISR"
msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Program does OUT without loading OSR"
msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Program must contain at least one 16-bit instruction."
msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Program size invalid"
msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Program too large"
msgstr ""
#: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/digitalio/DigitalInOut.c
msgid "Pull not used when direction is output." msgid "Pull not used when direction is output."
msgstr "" msgstr ""
@ -1753,6 +1867,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c #: ports/atmel-samd/common-hal/busio/I2C.c ports/esp32s2/common-hal/busio/I2C.c
#: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c #: ports/mimxrt10xx/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c
#: ports/raspberrypi/common-hal/busio/I2C.c
msgid "SDA or SCL needs a pull up" msgid "SDA or SCL needs a pull up"
msgstr "" msgstr ""
@ -1774,6 +1889,10 @@ msgstr ""
msgid "SPI Re-initialization error" msgid "SPI Re-initialization error"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/busio/SPI.c
msgid "SPI peripheral in use"
msgstr ""
#: shared-bindings/audiomixer/Mixer.c #: shared-bindings/audiomixer/Mixer.c
msgid "Sample rate must be positive" msgid "Sample rate must be positive"
msgstr "" msgstr ""
@ -1804,6 +1923,14 @@ msgstr ""
msgid "Server side context cannot have hostname" msgid "Server side context cannot have hostname"
msgstr "" msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Set pin count must be between 1 and 5"
msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Side set pin count must be between 1 and 5"
msgstr ""
#: ports/cxd56/common-hal/camera/Camera.c #: ports/cxd56/common-hal/camera/Camera.c
msgid "Size not supported" msgid "Size not supported"
msgstr "" msgstr ""
@ -1968,6 +2095,10 @@ msgstr ""
msgid "UART Re-init error" msgid "UART Re-init error"
msgstr "" msgstr ""
#: ports/raspberrypi/common-hal/busio/UART.c
msgid "UART not yet supported"
msgstr ""
#: ports/stm/common-hal/busio/UART.c #: ports/stm/common-hal/busio/UART.c
msgid "UART write error" msgid "UART write error"
msgstr "" msgstr ""
@ -2072,7 +2203,8 @@ msgid ""
msgstr "" msgstr ""
#: ports/atmel-samd/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/I2C.c #: ports/atmel-samd/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/I2C.c
#: ports/esp32s2/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c #: ports/esp32s2/common-hal/busio/UART.c
#: ports/raspberrypi/common-hal/busio/I2C.c ports/stm/common-hal/busio/I2C.c
msgid "Unsupported baudrate" msgid "Unsupported baudrate"
msgstr "" msgstr ""
@ -3521,6 +3653,14 @@ msgstr ""
msgid "pressing both buttons at start up.\n" msgid "pressing both buttons at start up.\n"
msgstr "" msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "pull_threshold must be between 1 and 32"
msgstr ""
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "push_threshold must be between 1 and 32"
msgstr ""
#: extmod/modutimeq.c #: extmod/modutimeq.c
msgid "queue overflow" msgid "queue overflow"
msgstr "" msgstr ""

View File

@ -0,0 +1,81 @@
#include "common-hal/countio/Counter.h"
#include "py/runtime.h"
#include "py/mpstate.h"
#include "supervisor/shared/translate.h"
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h"
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
void common_hal_countio_counter_construct(countio_counter_obj_t* self,
const mcu_pin_obj_t* pin_a) {
if (pwm_gpio_to_channel(pin_a->number) != PWM_CHAN_B) {
mp_raise_RuntimeError(translate("Pin must be on PWM Channel B"));
}
self->pin_a = pin_a->number;
self->slice_num = pwm_gpio_to_slice_num(self->pin_a);
pwm_clear_irq(self->slice_num);
pwm_set_irq_enabled(self->slice_num, true);
irq_set_exclusive_handler(PWM_IRQ_WRAP, counter_interrupt_handler);
irq_set_enabled(PWM_IRQ_WRAP, true);
pwm_config cfg = pwm_get_default_config();
pwm_config_set_clkdiv_mode(&cfg, PWM_DIV_B_RISING);
pwm_init(self->slice_num, &cfg, false);
gpio_set_function(self->pin_a, GPIO_FUNC_PWM);
self->count = 0;
claim_pin(pin_a);
MP_STATE_PORT(counting) = self;
pwm_set_enabled(self->slice_num, true);
}
bool common_hal_countio_counter_deinited(countio_counter_obj_t* self) {
return self->pin_a == 0;
}
void common_hal_countio_counter_deinit(countio_counter_obj_t* self) {
if (common_hal_countio_counter_deinited(self)) {
return;
}
pwm_set_enabled(self->slice_num, false);
pwm_set_irq_enabled(self->slice_num, false);
reset_pin_number(self->pin_a);
gpio_init(self->pin_a);
self->pin_a = 0;
self->slice_num = 0;
MP_STATE_PORT(counting) = NULL;
}
mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self) {
self->count += pwm_get_counter(self->slice_num);
pwm_set_counter(self->slice_num, 0);
return self->count;
}
void common_hal_countio_counter_set_count(countio_counter_obj_t* self,
mp_int_t new_count) {
pwm_set_counter(self->slice_num, 0);
self->count = new_count;
}
void common_hal_countio_counter_reset(countio_counter_obj_t* self){
pwm_set_counter(self->slice_num, 0);
self->count = 0;
}
void counter_interrupt_handler() {
countio_counter_obj_t *self = MP_STATE_PORT(counting);
pwm_clear_irq(self->slice_num);
self->count += 65536;
}

View File

@ -0,0 +1,19 @@
#ifndef MICROPY_INCLUDED_RASPBERRRYPI_COMMON_HAL_COUNTIO_COUNTER_H
#define MICROPY_INCLUDED_RASPBERRRYPI_COMMON_HAL_COUNTIO_COUNTER_H
#include "common-hal/microcontroller/Pin.h"
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
uint8_t pin_a;
uint8_t slice_num;
mp_int_t count;
} countio_counter_obj_t;
void counter_interrupt_handler();
#endif // MICROPY_INCLUDED_RASPBERRRYPI_COMMON_HAL_COUNTIO_COUNTER_H

View File

@ -0,0 +1 @@
//No countio module functions

View File

@ -40,7 +40,10 @@
// This also includes mpconfigboard.h. // This also includes mpconfigboard.h.
#include "py/circuitpy_mpconfig.h" #include "py/circuitpy_mpconfig.h"
//#include "peripherals/samd/dma.h"
#define MICROPY_PORT_ROOT_POINTERS \ #define MICROPY_PORT_ROOT_POINTERS \
CIRCUITPY_COMMON_ROOT_POINTERS; CIRCUITPY_COMMON_ROOT_POINTERS \
mp_obj_t counting;
#endif // __INCLUDED_MPCONFIGPORT_H #endif // __INCLUDED_MPCONFIGPORT_H

View File

@ -29,7 +29,6 @@ CIRCUITPY_PWMIO = 1
# Things that need to be implemented. # Things that need to be implemented.
CIRCUITPY_AUDIOBUSIO = 0 # Use PIO interally for I2S CIRCUITPY_AUDIOBUSIO = 0 # Use PIO interally for I2S
CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_COUNTIO = 0 # Use PWM interally
CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally
CIRCUITPY_I2CPERIPHERAL = 0 CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NVM = 0 CIRCUITPY_NVM = 0