summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgamblor21 <mark.komus@gmail.com>2021-02-23 19:26:11 -0600
committergamblor21 <mark.komus@gmail.com>2021-02-23 19:38:05 -0600
commit379f454ce6480376eccc8ccf378524d30fdace7a (patch)
treee8dc6dc90392266239a053898e38b316d6f3eb5f
parentacbf66dacc198588323d1887e2599acb5d71cf12 (diff)
Adding countio to rp2040
-rw-r--r--locale/circuitpython.pot150
-rw-r--r--ports/raspberrypi/common-hal/countio/Counter.c81
-rw-r--r--ports/raspberrypi/common-hal/countio/Counter.h19
-rw-r--r--ports/raspberrypi/common-hal/countio/__init__.c1
-rw-r--r--ports/raspberrypi/mpconfigport.h5
-rw-r--r--ports/raspberrypi/mpconfigport.mk1
6 files changed, 250 insertions, 7 deletions
diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot
index de902f62f..4fd6e9929 100644
--- a/locale/circuitpython.pot
+++ b/locale/circuitpython.pot
@@ -339,6 +339,10 @@ msgstr ""
msgid "All event channels in use"
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
msgid "All sync event channels in use"
msgstr ""
@@ -387,6 +391,7 @@ msgstr ""
#: ports/cxd56/common-hal/analogio/AnalogOut.c
#: ports/mimxrt10xx/common-hal/analogio/AnalogOut.c
#: ports/nrf/common-hal/analogio/AnalogOut.c
+#: ports/raspberrypi/common-hal/analogio/AnalogOut.c
msgid "AnalogOut functionality not supported"
msgstr ""
@@ -533,6 +538,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
#: ports/esp32s2/common-hal/displayio/ParallelBus.c
#: ports/nrf/common-hal/displayio/ParallelBus.c
+#: ports/raspberrypi/common-hal/displayio/ParallelBus.c
#, c-format
msgid "Bus pin %d is already in use"
msgstr ""
@@ -586,6 +592,7 @@ msgstr ""
#: ports/atmel-samd/common-hal/digitalio/DigitalInOut.c
#: ports/mimxrt10xx/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"
msgstr ""
@@ -863,7 +870,8 @@ msgstr ""
msgid "Error: Failure to bind"
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/neopixel_write/__init__.c
#: shared-bindings/terminalio/Terminal.c
@@ -1045,6 +1053,10 @@ msgstr ""
msgid "I2C Init Error"
msgstr ""
+#: ports/raspberrypi/common-hal/busio/I2C.c
+msgid "I2C peripheral in use"
+msgstr ""
+
#: shared-bindings/audiobusio/I2SOut.c
msgid "I2SOut not available"
msgstr ""
@@ -1068,6 +1080,10 @@ msgstr ""
msgid "Incorrect buffer size"
msgstr ""
+#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
+msgid "Init program size invalid"
+msgstr ""
+
#: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c
msgid "Initialization failed due to lack of memory"
msgstr ""
@@ -1080,6 +1096,31 @@ msgstr ""
msgid "Input/output error"
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
msgid "Insufficient authentication"
msgstr ""
@@ -1131,7 +1172,7 @@ msgstr ""
#: ports/atmel-samd/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"
msgstr ""
@@ -1225,6 +1266,8 @@ msgstr ""
#: ports/mimxrt10xx/common-hal/busio/I2C.c
#: ports/mimxrt10xx/common-hal/busio/SPI.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"
msgstr ""
@@ -1346,6 +1389,36 @@ msgstr ""
msgid "Missing MISO or MOSI Pin"
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
msgid "Must be a %q subclass."
msgstr ""
@@ -1399,14 +1472,14 @@ msgstr ""
#: ports/atmel-samd/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/stm/common-hal/busio/UART.c
+#: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "No RX pin"
msgstr ""
#: ports/atmel-samd/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/stm/common-hal/busio/UART.c
+#: ports/raspberrypi/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c
msgid "No TX pin"
msgstr ""
@@ -1463,6 +1536,10 @@ msgstr ""
msgid "No network with that ssid"
msgstr ""
+#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
+msgid "No out in program"
+msgstr ""
+
#: shared-module/touchio/TouchIn.c
msgid "No pulldown on pin; 1Mohm recommended"
msgstr ""
@@ -1518,6 +1595,10 @@ msgstr ""
msgid "Only 8 or 16 bit mono with "
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
msgid "Only IPv4 addresses supported"
msgstr ""
@@ -1602,11 +1683,20 @@ msgstr ""
msgid "Permission denied"
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/cxd56/common-hal/analogio/AnalogIn.c
#: ports/esp32s2/common-hal/analogio/AnalogIn.c
#: ports/mimxrt10xx/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
msgid "Pin does not have ADC capabilities"
msgstr ""
@@ -1616,6 +1706,10 @@ msgstr ""
msgid "Pin is input only"
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
msgid "Pin must support hardware interrupts"
msgstr ""
@@ -1667,6 +1761,26 @@ msgstr ""
msgid "Pretending to deep sleep until alarm, CTRL-C or file write.\n"
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
msgid "Pull not used when direction is output."
msgstr ""
@@ -1753,6 +1867,7 @@ msgstr ""
#: 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/raspberrypi/common-hal/busio/I2C.c
msgid "SDA or SCL needs a pull up"
msgstr ""
@@ -1774,6 +1889,10 @@ msgstr ""
msgid "SPI Re-initialization error"
msgstr ""
+#: ports/raspberrypi/common-hal/busio/SPI.c
+msgid "SPI peripheral in use"
+msgstr ""
+
#: shared-bindings/audiomixer/Mixer.c
msgid "Sample rate must be positive"
msgstr ""
@@ -1804,6 +1923,14 @@ msgstr ""
msgid "Server side context cannot have hostname"
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
msgid "Size not supported"
msgstr ""
@@ -1968,6 +2095,10 @@ msgstr ""
msgid "UART Re-init error"
msgstr ""
+#: ports/raspberrypi/common-hal/busio/UART.c
+msgid "UART not yet supported"
+msgstr ""
+
#: ports/stm/common-hal/busio/UART.c
msgid "UART write error"
msgstr ""
@@ -2072,7 +2203,8 @@ msgid ""
msgstr ""
#: 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"
msgstr ""
@@ -3521,6 +3653,14 @@ msgstr ""
msgid "pressing both buttons at start up.\n"
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
msgid "queue overflow"
msgstr ""
diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c
new file mode 100644
index 000000000..c5a47d2a4
--- /dev/null
+++ b/ports/raspberrypi/common-hal/countio/Counter.c
@@ -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;
+}
diff --git a/ports/raspberrypi/common-hal/countio/Counter.h b/ports/raspberrypi/common-hal/countio/Counter.h
new file mode 100644
index 000000000..201034cf4
--- /dev/null
+++ b/ports/raspberrypi/common-hal/countio/Counter.h
@@ -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
diff --git a/ports/raspberrypi/common-hal/countio/__init__.c b/ports/raspberrypi/common-hal/countio/__init__.c
new file mode 100644
index 000000000..b95b20d15
--- /dev/null
+++ b/ports/raspberrypi/common-hal/countio/__init__.c
@@ -0,0 +1 @@
+//No countio module functions
diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h
index 77d1ff080..b1165a3ba 100644
--- a/ports/raspberrypi/mpconfigport.h
+++ b/ports/raspberrypi/mpconfigport.h
@@ -40,7 +40,10 @@
// This also includes mpconfigboard.h.
#include "py/circuitpy_mpconfig.h"
+//#include "peripherals/samd/dma.h"
+
#define MICROPY_PORT_ROOT_POINTERS \
- CIRCUITPY_COMMON_ROOT_POINTERS;
+ CIRCUITPY_COMMON_ROOT_POINTERS \
+ mp_obj_t counting;
#endif // __INCLUDED_MPCONFIGPORT_H
diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk
index 138896d41..15e17cd6f 100644
--- a/ports/raspberrypi/mpconfigport.mk
+++ b/ports/raspberrypi/mpconfigport.mk
@@ -29,7 +29,6 @@ CIRCUITPY_PWMIO = 1
# Things that need to be implemented.
CIRCUITPY_AUDIOBUSIO = 0 # Use PIO interally for I2S
CIRCUITPY_AUDIOMP3 = 0
-CIRCUITPY_COUNTIO = 0 # Use PWM interally
CIRCUITPY_FREQUENCYIO = 0 # Use PWM interally
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NVM = 0