Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10e1b32bc1 |
@@ -8,13 +8,12 @@
|
||||
#include "task.h"
|
||||
|
||||
#define I2C_SDA NRF_GPIO_PIN_MAP(0, 11)
|
||||
#define I2C_SCL NRF_GPIO_PIN_MAP(0, 22)
|
||||
#define I2C_SCL NRF_GPIO_PIN_MAP(0, 2)
|
||||
|
||||
static const nrf_drv_twi_t twi0 = NRF_DRV_TWI_INSTANCE(0);
|
||||
static SemaphoreHandle_t i2c_sem = NULL;
|
||||
static SemaphoreHandle_t i2c_mutex = NULL;
|
||||
static QueueHandle_t i2c_evt_queue = NULL;
|
||||
|
||||
void nrf_drv_twi_evt_handler(nrf_drv_twi_evt_t const *p_event, void *p_context)
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
@@ -53,15 +52,12 @@ void twi0_init(void)
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_twi_enable(&twi0);
|
||||
|
||||
uint8_t buf[8];
|
||||
twi0_write_reg(0xAA, 0x01, buf, 8);
|
||||
}
|
||||
|
||||
void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len)
|
||||
{
|
||||
xSemaphoreTake(i2c_mutex, portMAX_DELAY);
|
||||
|
||||
|
||||
static uint8_t i2c_buf[255];
|
||||
static nrf_drv_twi_evt_t evt;
|
||||
ret_code_t err_code;
|
||||
@@ -79,7 +75,6 @@ void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t
|
||||
/* Transfer completed event. */
|
||||
case NRF_DRV_TWI_EVT_DONE:
|
||||
// TODO...
|
||||
__BKPT(255);
|
||||
break;
|
||||
/* Error event: NACK received after sending the address. */
|
||||
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
|
||||
@@ -118,7 +113,6 @@ void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint
|
||||
/* Transfer completed event. */
|
||||
case NRF_DRV_TWI_EVT_DONE:
|
||||
// TODO...
|
||||
__BKPT(255);
|
||||
break;
|
||||
/* Error event: NACK received after sending the address. */
|
||||
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
|
||||
@@ -143,7 +137,6 @@ void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint
|
||||
/* Transfer completed event. */
|
||||
case NRF_DRV_TWI_EVT_DONE:
|
||||
// TODO...
|
||||
__BKPT(255);
|
||||
break;
|
||||
/* Error event: NACK received after sending the address. */
|
||||
case NRF_DRV_TWI_EVT_ADDRESS_NACK:
|
||||
|
||||
@@ -190,6 +190,28 @@ static void enable_6994_callback(void *pvParameter)
|
||||
NRF_LOG_INFO("enable 6994");
|
||||
}
|
||||
|
||||
extern void twi0_write_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *data, uint8_t data_len);
|
||||
extern void twi0_read_reg(uint8_t slave_addr, uint8_t reg_addr, uint8_t *p_rx_buf, uint8_t rx_buffer_length);
|
||||
|
||||
void touch_sensor_task(void *pArg)
|
||||
{
|
||||
/*
|
||||
* pin assign:
|
||||
* SDA SCL INT VDD GND
|
||||
* p0.11 p0.02 p0.29 5V0 GND
|
||||
*/
|
||||
nrf_gpio_cfg_input(29, NRF_GPIO_PIN_NOPULL);//INT
|
||||
|
||||
for (;;)
|
||||
{
|
||||
bool button = nrf_gpio_pin_read(29);
|
||||
NRF_LOG_INFO("button=%d", button);
|
||||
uint8_t rx_buffer[1];
|
||||
twi0_read_reg(0x50, 0x0D, rx_buffer, 1);
|
||||
vTaskDelay(500);
|
||||
}
|
||||
}
|
||||
|
||||
static void nrf_sdh_freertos_task_hook(void *p_context)
|
||||
{
|
||||
extern void twi0_init(void);
|
||||
@@ -197,11 +219,13 @@ static void nrf_sdh_freertos_task_hook(void *p_context)
|
||||
|
||||
UNUSED_PARAMETER(p_context);
|
||||
|
||||
twi0_init();
|
||||
spi_init();
|
||||
gpio_init();
|
||||
spi_init();
|
||||
twi0_init();
|
||||
led_init();
|
||||
|
||||
xTaskCreate(touch_sensor_task, "touch_sensor_task", 256, NULL, 3, NULL);
|
||||
|
||||
NRF_LOG_INFO("LED_GREEN");
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user