Skip to content

Commit bdaec19

Browse files
eriknyquistsys_maker
authored and
sys_maker
committed
Add CurieIMUClass::end()
Add end() method to IMU class, to disable clocking to the SPI controller. This is unlikely to have noticeable power-saving effects, however it is a good habit to get into.
1 parent 2ec9b94 commit bdaec19

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

libraries/CurieIMU/src/CurieIMU.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ bool CurieIMUClass::begin()
5757
return (CURIE_IMU_CHIP_ID == getDeviceID());
5858
}
5959

60+
void CurieIMUClass::end()
61+
{
62+
ss_spi_disable();
63+
}
64+
6065
int CurieIMUClass::getGyroRate()
6166
{
6267
int rate;

libraries/CurieIMU/src/CurieIMU.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class CurieIMUClass : public BMI160Class {
9595

9696
public:
9797
bool begin(void);
98+
void end(void);
9899

99100
// supported values: 25, 50, 100, 200, 400, 800, 1600, 3200 (Hz)
100101
int getGyroRate();

libraries/CurieIMU/src/internal/ss_spi.c

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ void ss_spi_init()
7373
SS_SPI_REG_WRITE(INTR_MASK, SPI_DISABLE_INT);
7474
}
7575

76+
void ss_spi_disable()
77+
{
78+
/* gate SPI controller clock */
79+
SS_SPI_REG_WRITE(CTRL, 0);
80+
}
81+
7682
static inline
7783
void spi_transmit(uint8_t *buf, size_t count, boolean_t waitCompletion) {
7884
while (count--)

libraries/CurieIMU/src/internal/ss_spi.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#endif
2626

2727
void ss_spi_init();
28+
void ss_spi_disable();
2829
int ss_spi_xfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt);
2930

3031
#ifdef __cplusplus

0 commit comments

Comments
 (0)