-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Imu #519
base: integration
Are you sure you want to change the base?
Imu #519
Changes from 8 commits
8caf7d4
92a4f3e
eed9c0e
416b71d
4ddb1bf
d693719
61f184e
19ea239
56d93eb
1b18326
bfec65c
af4cade
d9832e2
e8cbf0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ enum imu_hz { | |
IMU_HZ_1 = 1, | ||
IMU_HZ_10 = 2, | ||
IMU_HZ_25 = 3, | ||
IMU_HZ_400 = 7, | ||
}; | ||
|
||
enum imu_accel_range { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,15 +166,19 @@ inline void imu_enable_all_axis() | |
_register_write(REG_CTRL_1, reg | (AXIS_ENABLE)); | ||
} | ||
|
||
void imu_clear_tap_interrupt(void){ | ||
uint8_t int_source; | ||
_register_read(REG_CLICK_SRC, &int_source); | ||
} | ||
inline uint8_t imu_clear_interrupt_status() | ||
{ | ||
|
||
// clear the interrupt by reading INT_SRC register | ||
uint8_t int_source; | ||
_register_read(REG_INT1_SRC, &int_source); | ||
PRINTF("INT CLR %x\r\n", int_source); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why move this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. artifact from testing, will revert |
||
imu_reset_hp_filter(); | ||
|
||
PRINTF("INT CLR %x\n", int_source); | ||
return int_source; | ||
} | ||
|
||
|
@@ -472,8 +476,28 @@ int32_t imu_init_simple(enum SPI_Channel channel, | |
APP_ASSERT(0); | ||
return -1; | ||
} | ||
|
||
imu_reset(); | ||
_register_write(REG_CTRL_4, BLOCKDATA_UPDATE);//80 | ||
|
||
return 0; | ||
} | ||
|
||
int32_t imu_tap_enable(void){ | ||
imu_enable_all_axis(); | ||
imu_set_accel_freq(IMU_HZ_400); | ||
_register_write(REG_CTRL_3, INT1_CLICK); | ||
_register_write(REG_CTRL_5, (LATCH_INTERRUPT1)); | ||
_register_write(REG_CTRL_6, INT_ACTIVE_LOW ); | ||
|
||
_register_write(REG_CLICK_CFG, 0x3F);//all directions clickable | ||
_register_write(REG_CLICK_SRC, CLICK_SRC_DCLICK | CLICK_SRC_STAP); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this register meant to be written to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like its read only, will remove |
||
_register_write(REG_CLICK_THR, 0xB0); | ||
_register_write(REG_TIME_LIMIT, 0x04); | ||
_register_write(REG_TIME_LATENCY, 0x24); | ||
_register_write(REG_TIME_WINDOW, 0x7F); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are the units for these documented anywhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, i just saw a youtube video of a demo and copied the numbers. |
||
|
||
return 0; | ||
} | ||
int32_t imu_init_low_power(enum SPI_Channel channel, enum SPI_Mode mode, | ||
uint8_t miso, uint8_t mosi, uint8_t sclk, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,17 @@ | |
#include <spi.h> | ||
#include <util.h> | ||
#include "imu.h" | ||
#include <nrf_gpio.h> | ||
#include <app_gpiote.h> | ||
#include "message_sspi.h" | ||
#include <app_timer.h> | ||
#include "platform.h" | ||
static const MSG_Central_t * parent; | ||
static app_gpiote_user_id_t _gpiote_user; | ||
static MSG_Base_t base; | ||
static char * name = "IMU"; | ||
static uint8_t flipped = 0; | ||
static app_timer_id_t _flip_timer; | ||
|
||
static MSG_Status _destroy(void){ | ||
return SUCCESS; | ||
|
@@ -15,9 +23,30 @@ static MSG_Status _flush(void){ | |
return SUCCESS; | ||
} | ||
|
||
static void _imu_gpiote_process(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low) | ||
{ | ||
imu_clear_tap_interrupt(); | ||
PRINTS("Tap\r\n"); | ||
MSG_Data_t * data = MSG_Base_AllocateStringAtomic("tap"); | ||
if(data){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not reference a const string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to convert the string to MSG_Data_t * which is consumed by the sspi module |
||
parent->dispatch( (MSG_Address_t){IMU, 0}, | ||
(MSG_Address_t){SSPI,MSG_SSPI_TEXT}, | ||
data); | ||
MSG_Base_ReleaseDataAtomic(data); | ||
} | ||
parent->dispatch( (MSG_Address_t){IMU, 0}, | ||
(MSG_Address_t){IMU,0}, | ||
NULL); | ||
} | ||
static MSG_Status _init(void){ | ||
#ifdef PLATFORM_HAS_ACCEL_SPI | ||
if(0 == imu_init_simple(SPI_Channel_0, SPI_Mode3, ACCEL_MISO, ACCEL_MOSI, ACCEL_SCLK, ACCEL_nCS)){ | ||
if( 0 == imu_init_simple(SPI_Channel_0, SPI_Mode3, ACCEL_MISO, ACCEL_MOSI, ACCEL_SCLK, ACCEL_nCS) | ||
&& 0 == imu_tap_enable() | ||
){ | ||
APP_OK(app_gpiote_user_enable(_gpiote_user)); | ||
imu_clear_interrupt_status(); | ||
imu_clear_tap_interrupt(); | ||
app_timer_start(_flip_timer, 250, NULL); | ||
return SUCCESS; | ||
}else{ | ||
return FAIL; | ||
|
@@ -26,6 +55,34 @@ static MSG_Status _init(void){ | |
return FAIL; | ||
#endif | ||
} | ||
static void _on_flip_timer(void* context){ | ||
int16_t xyz[3] = {0}; | ||
imu_accel_reg_read(xyz); | ||
/* | ||
*PRINTF("<imu>x:%d y:%d z:%d</imu>\r\n", xyz[0], xyz[1], xyz[2]); | ||
*/ | ||
if(xyz[2] > 1000 && !flipped){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is dependent on the selected scale There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, i don't think the scale matters in this, because this is a simple hysteresis on the Z value. Due to the orientation of the imu chip, any positive Z value means Sense has flipped or rolled. |
||
PRINTF("flipped"); | ||
MSG_Data_t * data = MSG_Base_AllocateStringAtomic("flipped 1"); | ||
if(data){ | ||
parent->dispatch( (MSG_Address_t){IMU, 0}, | ||
(MSG_Address_t){SSPI,MSG_SSPI_TEXT}, | ||
data); | ||
MSG_Base_ReleaseDataAtomic(data); | ||
} | ||
flipped = 1; | ||
}else if(xyz[2] < -1000 && flipped){ | ||
PRINTF("normal"); | ||
MSG_Data_t * data = MSG_Base_AllocateStringAtomic("flipped 0"); | ||
if(data){ | ||
parent->dispatch( (MSG_Address_t){IMU, 0}, | ||
(MSG_Address_t){SSPI,MSG_SSPI_TEXT}, | ||
data); | ||
MSG_Base_ReleaseDataAtomic(data); | ||
} | ||
flipped = 0; | ||
} | ||
} | ||
static MSG_Status _send(MSG_Address_t src, MSG_Address_t dst, MSG_Data_t * data){ | ||
return SUCCESS; | ||
} | ||
|
@@ -37,5 +94,9 @@ MSG_Base_t * MSG_IMU_Init(const MSG_Central_t * central){ | |
base.send = _send; | ||
base.type = IMU; | ||
base.typestr = name; | ||
nrf_gpio_cfg_input(ACCEL_INT, NRF_GPIO_PIN_NOPULL); | ||
APP_OK(app_gpiote_user_register(&_gpiote_user, 0, 1 << ACCEL_INT, _imu_gpiote_process)); | ||
APP_OK(app_gpiote_user_disable(_gpiote_user)); | ||
APP_OK(app_timer_create(&_flip_timer, APP_TIMER_MODE_REPEATED, _on_flip_timer)); | ||
return &base; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undocumented rates go all the way up to 1.6 kHz (the resonant freq of the sensing element) but you get reduced resolution...