minor changes

This commit is contained in:
Gunar Schorcht 2018-01-06 15:39:19 +01:00
parent 2d52ad85b4
commit 6e1bfd2845
3 changed files with 78 additions and 58 deletions

View file

@ -250,32 +250,25 @@ void user_init(void)
if (sensor)
{
// --- SYSTEM CONFIGURATION PART ----
#ifdef INT_USED
/** --- INTERRUPT CONFIGURATION PART ---- */
#if !defined (INT_USED)
// Interrupt configuration has to be done before the sensor is set
// into measurement mode to avoid losing interrupts
// create a user task that fetches data from sensor periodically
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
#else // INT_USED
// create a task that is triggered only in case of interrupts to fetch the data
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, NULL);
// create event queue
// create an event queue to send interrupt events from interrupt
// handler to the interrupt task
gpio_evt_queue = xQueueCreate(10, sizeof(uint8_t));
// configure interupt pins for *INT1* and *INT2* signals and set the interrupt handler
gpio_enable(INT1_PIN, GPIO_INPUT);
gpio_set_interrupt(INT1_PIN, GPIO_INTTYPE_EDGE_POS, int_signal_handler);
#endif // !defined(INT_USED)
#endif // INT_USED
// -- SENSOR CONFIGURATION PART ---
/** -- SENSOR CONFIGURATION PART --- */
// Interrupt configuration has to be done before the sensor is set
// into measurement mode
// set polarity of INT signals if necessary
// lis3dh_config_int_signals (sensor, lis3dh_high_active);
@ -351,7 +344,24 @@ void user_init(void)
lis3dh_set_scale(sensor, lis3dh_scale_2_g);
lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
// -- SENSOR CONFIGURATION PART ---
/** -- TASK CREATION PART --- */
// must be done last to avoid concurrency situations with the sensor
// configuration part
#ifdef INT_USED
// create a task that is triggered only in case of interrupts to fetch the data
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, NULL);
#else // INT_USED
// create a user task that fetches data from sensor periodically
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
#endif
}
else
printf("Could not initialize LIS3DH sensor\n");
}

View file

@ -581,9 +581,28 @@ sensor = lis3dh_init_sensor (SPI_BUS, 0, SPI_CS_GPIO);
The remaining of the program is independent on the communication interface.
#### Configuring the sensor
Optionally, you could wish to set some measurement parameters. For details see the sections above, the header file of the driver ```lis3dh.h```, and of course the data sheet of the sensor.
#### Starting measurements
As last step, the sensor mode has be set to start periodic measurement. The sensor mode can be changed anytime later.
```
...
// start periodic measurement with output data rate of 10 Hz
lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
...
```
#### Periodic user task
If initialization of the sensor was successful, the user task that uses the sensor has to be created. The user task can use different approaches to fetch new data. Either new data are fetched periodically or interrupt signals are used when new data are available or a configured event happens.
Finally, a user task that uses the sensor has to be created.
**Please note:** To avoid concurrency situations when driver functions are used to access the sensor, for example to read data, the user task must not be created until the sensor configuration is completed.
The user task can use different approaches to fetch new data. Either new data are fetched periodically or interrupt signals are used when new data are available or a configured event happens.
If new data are fetched **periodically** the implementation of the user task is quite simple and could look like following.
@ -677,21 +696,6 @@ gpio_set_interrupt(INT2_PIN, GPIO_INTTYPE_EDGE_POS, int_signal_handler);
Furthermore, the interrupts have to be enabled and configured in the LIS3DH sensor, see section **Interrupts** above.
#### Configuring the sensor
Optionally, you could wish to set some measurement parameters. For details see the sections above, the header file of the driver ```lis3dh.h```, and of course the data sheet of the sensor.
#### Starting measurements
As last step, the sensor mode has be set to start periodic measurement. The sensor mode can be changed anytime later.
```
...
// start periodic measurement with output data rate of 10 Hz
lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
...
```
## Full Example
```
@ -820,9 +824,11 @@ void user_task_interrupt (void *pvParameters)
// get the source of the interrupt and reset *INTx* signals
#ifdef INT_DATA
lis3dh_get_int_data_source (sensor, &data_src);
#elif INT_EVENT
#endif
#ifdef INT_EVENT
lis3dh_get_int_event_source (sensor, &event_src, lis3dh_int_event1_gen);
#elif INT_CLICK
#endif
#ifdef INT_CLICK
lis3dh_get_int_click_source (sensor, &click_src);
#endif
@ -915,32 +921,25 @@ void user_init(void)
if (sensor)
{
// --- SYSTEM CONFIGURATION PART ----
#ifdef INT_USED
/** --- INTERRUPT CONFIGURATION PART ---- */
#if !defined (INT_USED)
// Interrupt configuration has to be done before the sensor is set
// into measurement mode to avoid losing interrupts
// create a user task that fetches data from sensor periodically
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
#else // INT_USED
// create a task that is triggered only in case of interrupts to fetch the data
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, NULL);
// create event queue
// create an event queue to send interrupt events from interrupt
// handler to the interrupt task
gpio_evt_queue = xQueueCreate(10, sizeof(uint8_t));
// configure interupt pins for *INT1* and *INT2* signals and set the interrupt handler
gpio_enable(INT1_PIN, GPIO_INPUT);
gpio_set_interrupt(INT1_PIN, GPIO_INTTYPE_EDGE_POS, int_signal_handler);
#endif // !defined(INT_USED)
#endif // INT_USED
// -- SENSOR CONFIGURATION PART ---
/** -- SENSOR CONFIGURATION PART --- */
// Interrupt configuration has to be done before the sensor is set
// into measurement mode
// set polarity of INT signals if necessary
// lis3dh_config_int_signals (sensor, lis3dh_high_active);
@ -1016,8 +1015,25 @@ void user_init(void)
lis3dh_set_scale(sensor, lis3dh_scale_2_g);
lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
// -- SENSOR CONFIGURATION PART ---
/** -- TASK CREATION PART --- */
// must be done last to avoid concurrency situations with the sensor
// configuration part
#ifdef INT_USED
// create a task that is triggered only in case of interrupts to fetch the data
xTaskCreate(user_task_interrupt, "user_task_interrupt", TASK_STACK_DEPTH, NULL, 2, NULL);
#else // INT_USED
// create a user task that fetches data from sensor periodically
xTaskCreate(user_task_periodic, "user_task_periodic", TASK_STACK_DEPTH, NULL, 2, NULL);
#endif
}
else
printf("Could not initialize LIS3DH sensor\n");
}
```

View file

@ -66,12 +66,6 @@
#include "esp/spi.h"
#include "i2c/i2c.h"
// platform specific definitions
#define spi_semaphore_init(d)
#define spi_semaphore_take(d)
#define spi_semaphore_give(d)
// platform specific SPI functions
#define spi_bus_init(bus,sck,miso,mosi) // not needed on ESP8266