Added encoders.pio from mdxtinkernick and fixed makefile

This commit is contained in:
Nicholas Gadjali
2021-03-07 21:11:56 -08:00
parent ae9cc13edd
commit ff86b07e2a
126 changed files with 8032 additions and 684 deletions
+12 -4
View File
@@ -1,9 +1,17 @@
add_executable(pico_sdvx
pico_sdvx.c
usb_descriptors.c
)
usb_descriptors.c)
target_include_directories(pico_sdvx PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(pico_sdvx PRIVATE pico_stdlib tinyusb_device tinyusb_board)
pico_add_extra_outputs(pico_sdvx)
pico_generate_pio_header(pico_sdvx ${CMAKE_CURRENT_LIST_DIR}/encoders.pio)
target_sources(pico_sdvx PRIVATE pico_sdvx.c)
target_link_libraries(pico_sdvx PRIVATE
pico_stdlib
tinyusb_device
tinyusb_board
hardware_dma
hardware_irq)
pico_add_extra_outputs(pico_sdvx)
+53
View File
@@ -0,0 +1,53 @@
.program encoders
.wrap_target
in pins, 2 ; read the two pins to get value
mov y, isr ; put it in y to make comparison later
checking:
set x, 0
mov isr, x ; clear values ready for next reading
in pins, 2 ; read latest value
mov x, isr ; mov to x to make comparison
jmp x!=y on_change ; compare
jmp checking ; check again if same
on_change:
mov x, osr ; move contents of osr to x - this is the count
mov osr, y ; move previous value in osr in order get the single bit
out y, 1 ; get the individual bit
jmp y-- was_zero ; if its now zeronon zero then it was zero before
jmp pin inc ; it was 1 so if other pins 1 then inc
jmp dec ; otherwise dec
was_zero:
jmp pin dec ; different so dec, otherwise fall through and inc
inc:
mov x, !x
jmp x-- fake ; just need to dec and fall through
fake:
mov x, !x ; inc complete
jmp send
dec:
jmp x-- send ; jump to send, or fall through to send - really just dec
send:
mov isr, x ; move count to isr
push ; send it out (also clears isr ready for next read)
mov osr, x ; move count to osr so can use x and y for comparison again
.wrap
% c-sdk {
static inline void encoders_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false);
pio_gpio_init(pio, pin);
pio_gpio_init(pio, pin+1);
gpio_pull_up(pin);
gpio_pull_up(pin+1);
pio_sm_config c = encoders_program_get_default_config(offset);
sm_config_set_in_pins(&c, pin);
sm_config_set_jmp_pin(&c, pin +1);
// Shift to left, autopull disabled
sm_config_set_in_shift(&c, false, false, 2);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}
+4 -1
View File
@@ -2,7 +2,7 @@
* Pico SDVX
* @author SpeedyPotato
*
* Based off dev_hid_composite and PaulStoffregen/Encoder
* Based off dev_hid_composite and mdxtinkernick/pico_encoders
*/
#include <stdlib.h>
@@ -15,6 +15,9 @@
#include "usb_descriptors.h"
// #include "hardware/pio.h"
// #include "encoders.pio.h"
const uint8_t SW_KEYCODE[] = {HID_KEY_RETURN, HID_KEY_A, HID_KEY_S, HID_KEY_D, HID_KEY_F, HID_KEY_Z, HID_KEY_X}; // MODIFY KEYBINDS HERE
const uint8_t SW_GPIO[] = {4, 5, 6, 7, 8, 9, 10}; // MAKE SURE SW_KEYCODE and SW_GPIO LENGTHS MATCH
const uint8_t LED_GPIO[] = {28, 27, 26, 22, 21, 20, 19}; // MAKE SURE SW_GPIO and LED_GPIO LENGTHS MATCH