From 316e1f292c603885f2af3dcd69ce797d64776425 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sun, 5 Dec 2021 23:06:25 -0600 Subject: rename project files --- apps/spi-test/app.c | 71 +++++++++++++++++++++++++++++++++++++++++++ apps/spi-test/make/.gitignore | 1 + apps/spi-test/make/Makefile | 10 ++++++ 3 files changed, 82 insertions(+) create mode 100644 apps/spi-test/app.c create mode 100755 apps/spi-test/make/.gitignore create mode 100755 apps/spi-test/make/Makefile (limited to 'apps/spi-test') diff --git a/apps/spi-test/app.c b/apps/spi-test/app.c new file mode 100644 index 00000000..3fba9386 --- /dev/null +++ b/apps/spi-test/app.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include "watch.h" + +// NOTE: as of this writing (10/25/21) there is no SPI controller functionality in the watch library. +// this is a very basic app to confirm that SPI is working, tested with board OSO-MISC-21-001 and a GD25Q16C Flash chip. +// The updated SPI Flash sensor board design is OSO-MISC-21-017 (it's easier to build, 0603 passives instead of 0402's). + +struct io_descriptor *io; +struct spi_m_sync_descriptor SPI_0; + +void app_init() { + // SPI_0_CLOCK_init + hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); + hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); + hri_mclk_set_APBCMASK_SERCOM3_bit(MCLK); + + spi_m_sync_init(&SPI_0, SERCOM3); + + // SPI_0_PORT_init + gpio_set_pin_level(A3, true); + gpio_set_pin_direction(A3, GPIO_DIRECTION_OUT); + gpio_set_pin_function(A3, GPIO_PIN_FUNCTION_OFF); + + gpio_set_pin_level(A2, false); + gpio_set_pin_direction(A2, GPIO_DIRECTION_OUT); + gpio_set_pin_function(A2, PINMUX_PB02C_SERCOM3_PAD0); + + gpio_set_pin_direction(A4, GPIO_DIRECTION_IN); + gpio_set_pin_pull_mode(A4, GPIO_PULL_OFF); + gpio_set_pin_function(A4, PINMUX_PB00C_SERCOM3_PAD2); + + gpio_set_pin_level(A1, false); + gpio_set_pin_direction(A1, GPIO_DIRECTION_OUT); + gpio_set_pin_function(A1, PINMUX_PB01C_SERCOM3_PAD3); + + spi_m_sync_get_io_descriptor(&SPI_0, &io); + spi_m_sync_enable(&SPI_0); +} + +void app_wake_from_backup() { +} + +void app_setup() { +} + +void app_prepare_for_standby() { +} + +void app_wake_from_standby() { +} + +static uint8_t get_id_command[4] = {0x9F}; + +bool app_loop() { + watch_set_pin_level(A3, false); + io_write(io, get_id_command, 1); + uint8_t buf[3] = {0}; + + // should print 0, 0, 0 + printf("blank: %x, %x, %x\n", buf[0], buf[1], buf[2]); + io_read(io, buf, 3); + watch_set_pin_level(A3, true); + // should print c8, 40, 15 + printf("ident: %x, %x, %x\n", buf[0], buf[1], buf[2]); + + delay_ms(100); + + return false; +} diff --git a/apps/spi-test/make/.gitignore b/apps/spi-test/make/.gitignore new file mode 100755 index 00000000..3722ac63 --- /dev/null +++ b/apps/spi-test/make/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/apps/spi-test/make/Makefile b/apps/spi-test/make/Makefile new file mode 100755 index 00000000..c66ad20c --- /dev/null +++ b/apps/spi-test/make/Makefile @@ -0,0 +1,10 @@ +TOP = ../../.. +include $(TOP)/make.mk + +INCLUDES += \ + -I../ + +SRCS += \ + ../app.c + +include $(TOP)/rules.mk -- cgit v1.2.3 From 762af872d2f2c977e51d6e51b8c3ad622485cc05 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sun, 5 Dec 2021 23:49:26 -0600 Subject: fix missing prototype warnings --- apps/spi-test/app.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'apps/spi-test') diff --git a/apps/spi-test/app.c b/apps/spi-test/app.c index 3fba9386..6ddd2782 100644 --- a/apps/spi-test/app.c +++ b/apps/spi-test/app.c @@ -10,7 +10,7 @@ struct io_descriptor *io; struct spi_m_sync_descriptor SPI_0; -void app_init() { +void app_init(void) { // SPI_0_CLOCK_init hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_CORE, CONF_GCLK_SERCOM3_CORE_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SERCOM3_GCLK_ID_SLOW, CONF_GCLK_SERCOM3_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); @@ -39,21 +39,21 @@ void app_init() { spi_m_sync_enable(&SPI_0); } -void app_wake_from_backup() { +void app_wake_from_backup(void) { } -void app_setup() { +void app_setup(void) { } -void app_prepare_for_standby() { +void app_prepare_for_standby(void) { } -void app_wake_from_standby() { +void app_wake_from_standby(void) { } static uint8_t get_id_command[4] = {0x9F}; -bool app_loop() { +bool app_loop(void) { watch_set_pin_level(A3, false); io_write(io, get_id_command, 1); uint8_t buf[3] = {0}; -- cgit v1.2.3