Skip to content

Commit

Permalink
Added SPI driver
Browse files Browse the repository at this point in the history
  • Loading branch information
antsand committed Jun 5, 2023
1 parent 1e4bb0b commit 887aa6d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ CONFIG_ASSERT=y
# drivers
CONFIG_PWM=y
CONFIG_I2C=y

CONFIG_PWM_LOG_LEVEL_DBG=y

#SPI
CONFIG_SPI=y
CONFIG_NRFX_SPIM3=y
CONFIG_NRFX_SPIM4=y
CONFIG_SPI_ASYNC=y
CONFIG_SPI_SLAVE=y
9 changes: 9 additions & 0 deletions src/drivers/GPIO_INPUT/gpio_input_local.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "../../includes.h"
#include "gpio_input_local.h"


void button_pressed(const struct device *dev, struct gpio_callback *cb,
uint32_t pins)
{
printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
}
25 changes: 25 additions & 0 deletions src/drivers/GPIO_INPUT/gpio_input_local.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../../includes.h"

/*** Initilize GPIO input */
/*
* Get button configuration from the devicetree sw0 alias. This is mandatory.
*/
#define SW0_NODE DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_NODE, okay)
#error "Unsupported board: sw0 devicetree alias is not defined"
#endif

static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
{0});
static struct gpio_callback button_cb_data;

/*
* The led0 devicetree alias is optional. If present, we'll use it
* to turn on the LED whenever the button is pressed.
*/
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
{0});


void button_pressed(const struct device *dev, struct gpio_callback *cb,
uint32_t pins);
18 changes: 18 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "includes.h"
#include "drivers/PWM/pwm_local.h"
#include "drivers/SPIM/spim_local.h"
#include "drivers/GPIO_INPUT/gpio_input_local.h"

#define SLEEP_TIME_MS 1

#define LOG_MODULE_NAME peripheral_uart
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
Expand Down Expand Up @@ -561,6 +564,8 @@ void main(void)
setDuty(pwm_led1, period, period / 2U);
setDuty(pwm_led2, period, period / 10U);
setDuty(pwm_led3, period, period / 10U);

spi_init();

err = uart_init();
if (err) {
Expand Down Expand Up @@ -610,6 +615,19 @@ void main(void)
for (;;) {
dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));

/* Interfacting with sensor using SPI */
err = gpio_pin_toggle_dt(&spi4_cs);
if (err < 0)
{
return;
}
k_msleep(SLEEP_TIME_MS);
spi_write_test_msg();
err = gpio_pin_toggle_dt(&spi4_cs);
/* end sending info using SPI */

k_sleep(K_SECONDS(4U));
}
}

Expand Down

0 comments on commit 887aa6d

Please sign in to comment.