7
7
8
8
#include "acc_board.h"
9
9
#include "acc_device_gpio.h"
10
- #include "acc_driver_gpio_linux_sysfs.h"
11
- #include "acc_driver_spi_linux_spidev.h"
12
- #include "acc_log.h"
13
10
#include "acc_device_os.h"
14
11
#include "acc_device_spi.h"
12
+ #include "acc_driver_gpio_linux_sysfs.h"
15
13
#include "acc_driver_os_linux.h"
14
+ #include "acc_driver_spi_linux_spidev.h"
15
+ #include "acc_log.h"
16
+
16
17
17
18
/**
18
19
* @brief The module name
19
20
*
20
21
* Must exist if acc_log.h is used.
21
22
*/
22
- #define MODULE "acc_board_rpi_sparkx"
23
+ #define MODULE "acc_board_rpi_sparkx-3_r1c "
23
24
24
25
/**
25
26
* @brief The number of sensors available on the board
53
54
/**
54
55
* @brief The SPI speed of this board
55
56
*/
56
- //#define ACC_BOARD_SPI_SPEED 15000000
57
- #define ACC_BOARD_SPI_SPEED 1000000
57
+ #define ACC_BOARD_SPI_SPEED 15000000
58
58
59
59
/**
60
60
* @brief The SPI bus all sensors are using
@@ -87,9 +87,11 @@ static const uint_fast8_t sensor_interrupt_pins[SENSOR_COUNT] = {
87
87
GPIO0_PIN
88
88
};
89
89
90
+
90
91
static acc_board_isr_t master_isr ;
92
+ static acc_device_handle_t spi_handle ;
91
93
92
- static void isr_sensor1 (void ) { if (master_isr ) master_isr (1 ); }
94
+ static void isr_sensor1 (void ) { if (master_isr ) master_isr (1 );}
93
95
94
96
95
97
/**
@@ -131,17 +133,15 @@ acc_status_t acc_board_gpio_init(void)
131
133
if (
132
134
(status = acc_device_gpio_set_initial_pull (GPIO0_PIN , 0 )) ||
133
135
(status = acc_device_gpio_set_initial_pull (RSTn_PIN , 1 )) ||
134
- (status = acc_device_gpio_set_initial_pull (ENABLE_PIN , 0 ))// ||
135
- //(status = acc_device_gpio_set_initial_pull(CE_PIN, 1))
136
+ (status = acc_device_gpio_set_initial_pull (ENABLE_PIN , 0 ))
136
137
) {
137
138
ACC_LOG_WARNING ("%s: failed to set initial pull with status: %s" , __func__ , acc_log_status_name (status ));
138
139
}
139
140
140
141
if (
141
142
(status = acc_device_gpio_input (GPIO0_PIN )) ||
142
143
(status = acc_device_gpio_write (RSTn_PIN , 0 )) ||
143
- (status = acc_device_gpio_write (ENABLE_PIN , 0 ))// ||
144
- //(status = acc_device_gpio_write(CE_PIN, 1))
144
+ (status = acc_device_gpio_write (ENABLE_PIN , 0 ))
145
145
) {
146
146
ACC_LOG_ERROR ("%s failed with %s" , __func__ , acc_log_status_name (status ));
147
147
acc_os_mutex_unlock (init_mutex );
@@ -177,6 +177,17 @@ acc_status_t acc_board_init(void)
177
177
acc_driver_gpio_linux_sysfs_register (28 );
178
178
acc_driver_spi_linux_spidev_register ();
179
179
180
+ acc_device_gpio_init ();
181
+
182
+ acc_device_spi_configuration_t configuration ;
183
+ configuration .bus = ACC_BOARD_BUS ;
184
+ configuration .configuration = NULL ;
185
+ configuration .device = ACC_BOARD_CS ;
186
+ configuration .master = true;
187
+ configuration .speed = ACC_BOARD_SPI_SPEED ;
188
+
189
+ spi_handle = acc_device_spi_create (& configuration );
190
+
180
191
for (uint_fast8_t sensor_index = 0 ; sensor_index < SENSOR_COUNT ; sensor_index ++ ) {
181
192
sensor_state [sensor_index ] = SENSOR_STATE_UNKNOWN ;
182
193
}
@@ -232,6 +243,9 @@ acc_status_t acc_board_start_sensor(acc_sensor_t sensor)
232
243
return status ;
233
244
}
234
245
246
+ // Wait for PMU to stabilize
247
+ acc_os_sleep_us (5000 );
248
+
235
249
status = acc_device_gpio_write (ENABLE_PIN , 1 );
236
250
if (status != ACC_STATUS_SUCCESS ) {
237
251
ACC_LOG_ERROR ("Unable to activate ENABLE" );
@@ -282,41 +296,10 @@ acc_status_t acc_board_stop_sensor(acc_sensor_t sensor)
282
296
}
283
297
284
298
285
- void acc_board_get_spi_bus_cs (acc_sensor_t sensor , uint_fast8_t * bus , uint_fast8_t * cs )
286
- {
287
- if ((sensor <= 0 ) || (sensor > SENSOR_COUNT )) {
288
- * bus = -1 ;
289
- * cs = -1 ;
290
- } else {
291
- * bus = ACC_BOARD_BUS ;
292
- * cs = ACC_BOARD_CS ;
293
- }
294
- }
295
-
296
-
297
299
acc_status_t acc_board_chip_select (acc_sensor_t sensor , uint_fast8_t cs_assert )
298
300
{
299
301
ACC_UNUSED (sensor );
300
302
ACC_UNUSED (cs_assert );
301
- /*acc_status_t status;
302
-
303
- if (cs_assert) {
304
- uint_fast8_t cea_val = (sensor == 1 || sensor == 2) ? 0 : 1;
305
- uint_fast8_t ceb_val = (sensor == 1 || sensor == 3) ? 0 : 1;
306
-
307
- if (
308
- (status = acc_device_gpio_write(CE_A_PIN, cea_val)) ||
309
- (status = acc_device_gpio_write(CE_B_PIN, ceb_val))
310
- ) {
311
- ACC_LOG_ERROR("%s failed with %s", __func__, acc_log_status_name(status));
312
- return status;
313
- }
314
- status = acc_device_gpio_write(CE_PIN, 0);
315
- if (status) {
316
- ACC_LOG_ERROR("%s failed with %s", __func__, acc_log_status_name(status));
317
- return status;
318
- }
319
- }*/
320
303
321
304
return ACC_STATUS_SUCCESS ;
322
305
}
@@ -332,7 +315,7 @@ bool acc_board_is_sensor_interrupt_connected(acc_sensor_t sensor)
332
315
{
333
316
ACC_UNUSED (sensor );
334
317
335
- return false ;
318
+ return true ;
336
319
}
337
320
338
321
@@ -384,17 +367,38 @@ float acc_board_get_ref_freq(void)
384
367
}
385
368
386
369
387
- uint32_t acc_board_get_spi_speed ( uint_fast8_t bus )
370
+ acc_status_t acc_board_set_ref_freq ( float ref_freq )
388
371
{
389
- ACC_UNUSED (bus );
372
+ ACC_UNUSED (ref_freq );
390
373
391
- return ACC_BOARD_SPI_SPEED ;
374
+ return ACC_STATUS_UNSUPPORTED ;
392
375
}
393
376
394
377
395
- acc_status_t acc_board_set_ref_freq ( float ref_freq )
378
+ acc_status_t acc_board_sensor_transfer ( acc_sensor_t sensor_id , uint8_t * buffer , size_t buffer_length )
396
379
{
397
- ACC_UNUSED (ref_freq );
380
+ acc_status_t status ;
381
+ uint_fast8_t bus = acc_device_spi_get_bus (spi_handle );
398
382
399
- return ACC_STATUS_UNSUPPORTED ;
400
- }
383
+ acc_device_spi_lock (bus );
384
+
385
+ if ((status = acc_board_chip_select (sensor_id , 1 ))) {
386
+ ACC_LOG_ERROR ("%s failed with %s" , __func__ , acc_log_status_name (status ));
387
+ acc_device_spi_unlock (bus );
388
+ return status ;
389
+ }
390
+
391
+ if ((status = acc_device_spi_transfer (spi_handle , buffer , buffer_length ))) {
392
+ acc_device_spi_unlock (bus );
393
+ return status ;
394
+ }
395
+
396
+ if ((status = acc_board_chip_select (sensor_id , 0 ))) {
397
+ acc_device_spi_unlock (bus );
398
+ return status ;
399
+ }
400
+
401
+ acc_device_spi_unlock (bus );
402
+
403
+ return status ;
404
+ }
0 commit comments