diff --git a/circuit/README.md b/circuit/README.md index 4d003fc1e38ee92cbb003f04a7cfabbb73245bdd..c0c74bad49cfacdf599a22e90b851a3a6efd5a28 100644 --- a/circuit/README.md +++ b/circuit/README.md @@ -374,10 +374,50 @@ OK, enough for that wakeup, now I'm going to try to boot the USB CDC driver. Thi So, USB is a protocol, UART over USB is what the USB CDC lets you do. This is reductionist - and this also takes up some chunk of processor time, as far as I know - however, the chip has a USB peripheral, so I imagine most of the work is offloaded there. I would be tangentially interested in integrating a USB->Serial chip to compare processor overhead for the USB CDC implementation, but what am I trying to do here? Not that. +I couldn't get this running, not sure if that was about my clock, or what - but after one day lost, I give up. I'm going to build a USB -> UART RS485 Bridge (I also need a power injector, so this is all good) and go forwards with port testing and setup. +## Port Abstractions -USB CDC, interrupts -CDC, / mods pipe -> pass objects don't parse characters: key: value +Pins are on Ports, UARTS are on Ports, everything is confusing and ugly if we just write C and bang on registers. -Writeup PR2, do encoder? -or, do 2nd board, do uart return test, order next boards, dream of experiments +```C + +#ifndef PIN_H_ +#define PIN_H_ + +#include <stdlib.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "ASF/sam/utils/cmsis/sams70/include/sams70n20.h" + +typedef struct{ + Pio *port; + uint32_t pin_bm; +}pin_t; + +pin_t pin_new(Pio *port, uint32_t pin_bitmask); + +#endif /* PIN_H_ */ +``` + +and + +```C +#include "pin.h" +#include <asf.h> + +pin_t pin_new(Pio *port, uint32_t pin_bitmask){ + pin_t pin; + + pin.port = port; + pin.pin_bm = pin_bitmask; + + return pin; +} + +void pin_output(pin_t pin){ +} +``` + +to begin abstracting pins - just a struct \ No newline at end of file diff --git a/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo b/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo index daae7fc4f4629c19900d78c8c8a4f454640fe1c6..8790a3bab408f917685f581c8090ddb9fea3c097 100644 Binary files a/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo and b/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/atsams70-tinyrouter.bin b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/atsams70-tinyrouter.bin index bb479f3000037b104e66d75455b972317b929234..09c63abe7e8f195fe04283413c99aec87407663e 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/atsams70-tinyrouter.bin and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/atsams70-tinyrouter.bin differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/boards/user_board/init.o b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/boards/user_board/init.o index 0d8c4d83ae0f241b3b0148a17f7ff7b58f7c0245..46842522ca74f2ff8c1dba839749c1d983c833dc 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/boards/user_board/init.o and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/boards/user_board/init.o differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/services/clock/sams70/sysclk.o b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/services/clock/sams70/sysclk.o index fbf63d8f3dfe83c23e77396f5ceee84734ed6174..3fb097cdfe1bd207b40c3763654c59fe914aee09 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/services/clock/sams70/sysclk.o and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/common/services/clock/sams70/sysclk.o differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/sam/drivers/pmc/sleep.o b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/sam/drivers/pmc/sleep.o index a3c991bf542e4e0abbc2ddd3d0c753b3c05f38cf..8c19151f4eaf84eb817d4888c135515ff8021a21 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/sam/drivers/pmc/sleep.o and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/ASF/sam/drivers/pmc/sleep.o differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/main.o b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/main.o index 170686ee436d8e2710a7dd11cf90fd51198a49c7..8088fec857374725b6f6648405a43919cd6ad874 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/main.o and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/main.o differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/pin.o b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/pin.o index 074413a2a44bea358f2b14dfdeb36eaaec3cd743..0c101f6f735acf033ebc5d6f832d5e08e6d83af4 100644 Binary files a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/pin.o and b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/Debug/src/pin.o differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/config/conf_board.h b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/config/conf_board.h index 7b88c97fc205be08107659cf807daf0d37d718c8..112d55f87597c84e6910f127e722d0584338dcdb 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/config/conf_board.h +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/config/conf_board.h @@ -11,4 +11,14 @@ #ifndef CONF_BOARD_H #define CONF_BOARD_H +# define BOARD_FREQ_SLCK_XTAL (32768UL) + +# define BOARD_FREQ_SLCK_BYPASS (32768UL) + +# define BOARD_FREQ_MAINCK_XTAL (12000000UL) + +# define BOARD_FREQ_MAINCK_BYPASS (12000000UL) + +# define BOARD_OSC_STARTUP_US (15625UL) + #endif // CONF_BOARD_H diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c index 8a1916aeffd716a4361bbc3955598cb0f0f22124..22a5081802c4c3d08ef4516288d67c09f52f0d5e 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c @@ -32,6 +32,8 @@ #include "pin.h" pin_t stlb; +pin_t stlr; +pin_t button; int main (void) { @@ -41,20 +43,24 @@ int main (void) sysclk_init(); PMC->PMC_PCER0 = 1 << ID_PIOA; + PMC->PMC_PCER0 = 1 << ID_PIOD; stlb = pin_new(PIOA, PIO_PER_P1); + pin_output(stlb); - stlb.port->PIO_PER = stlb.pin_bm; - stlb.port->PIO_OER = stlb.pin_bm; + stlr = pin_new(PIOD, PIO_PER_P11); + pin_output(stlr); - PIOA->PIO_PER = PIO_PER_P15; - PIOA->PIO_ODR = PIO_PER_P15; + button = pin_new(PIOA, PIO_PER_P15); + pin_input(button); while(1){ - if(PIOA->PIO_PDSR & PIO_PER_P15){ - stlb.port->PIO_CODR = stlb.pin_bm; + if(pin_get_state(button)){ + pin_clear(stlb); + pin_set(stlr); } else { - stlb.port->PIO_SODR = stlb.pin_bm; + pin_set(stlb); + pin_clear(stlr); } } } diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.c b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.c index 008451f7b54647d43af37dc0eb168f8dc8d8d63a..fb672f5cd31d25c9bc519ee24c81830aad30e101 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.c +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.c @@ -15,4 +15,30 @@ pin_t pin_new(Pio *port, uint32_t pin_bitmask){ pin.pin_bm = pin_bitmask; return pin; +} + +void pin_output(pin_t pin){ + pin.port->PIO_PER |= pin.pin_bm; + pin.port->PIO_OER = pin.pin_bm; +} + +void pin_set(pin_t pin){ + pin.port->PIO_SODR = pin.pin_bm; +} + +void pin_clear(pin_t pin){ + pin.port->PIO_CODR = pin.pin_bm; +} + +void pin_input(pin_t pin){ + pin.port->PIO_PER |= pin.pin_bm; + pin.port->PIO_ODR = pin.pin_bm; +} + +bool pin_get_state(pin_t pin){ + if(pin.port->PIO_PDSR & pin.pin_bm){ + return true; + } else { + return false; + } } \ No newline at end of file diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.h b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.h index ca15e77db24c7695d1d464df61f542a1a8f78e90..8389b2630ed5dcf40b67a419a6b215e9a0fc78f5 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.h +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/pin.h @@ -22,4 +22,11 @@ typedef struct{ pin_t pin_new(Pio *port, uint32_t pin_bitmask); +void pin_output(pin_t pin); // set as output +void pin_set(pin_t pin); +void pin_clear(pin_t pin); + +void pin_input(pin_t pin); +bool pin_get_state(pin_t pin); + #endif /* PIN_H_ */ \ No newline at end of file