Skip to content

Commit d221671

Browse files
committed
altos: Add SPI bus parameter to ao_spi_speed
The stm32f1 series has two SPI busses and they operate from different base clocks, so the computation of the clock divider to get a particular frequency depends upon which SPI bus is being used. Signed-off-by: Keith Packard <[email protected]>
1 parent 3fdf2f8 commit d221671

20 files changed

+25
-20
lines changed

src/drivers/ao_adxl375.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define PRINTD(l,...)
2727
#endif
2828

29-
#define AO_ADXL375_SPI_SPEED ao_spi_speed(5000000)
29+
#define AO_ADXL375_SPI_SPEED ao_spi_speed(AO_ADXL375_SPI_INDEX, 5000000)
3030

3131
struct ao_adxl375_sample ao_adxl375_current;
3232

src/drivers/ao_bmi088.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <ao_bmi088.h>
2121
#include <ao_data.h>
2222

23-
#define AO_BMI088_SPI_SPEED ao_spi_speed(100000)
23+
#define AO_BMI088_SPI_SPEED ao_spi_speed(AO_BMI088_SPI_BUS, 100000)
2424

2525
#define ao_bmi088_spi_get() ao_spi_get(AO_BMI088_SPI_BUS, AO_BMI088_SPI_SPEED)
2626
#define ao_bmi088_spi_put() ao_spi_put(AO_BMI088_SPI_BUS)

src/drivers/ao_bmx160.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static uint8_t ao_bmx160_configured;
2424

2525
static struct ao_bmm150_trim ao_bmm150_trim;
2626

27-
#define AO_BMX160_SPI_SPEED ao_spi_speed(10000000)
27+
#define AO_BMX160_SPI_SPEED ao_spi_speed(AO_BMX160_SPI_BUS, 10000000)
2828

2929
#define ao_bmx160_spi_get() ao_spi_get(AO_BMX160_SPI_BUS, AO_BMX160_SPI_SPEED)
3030
#define ao_bmx160_spi_put() ao_spi_put(AO_BMX160_SPI_BUS)

src/drivers/ao_cc1120.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern const uint32_t ao_radio_cal;
4242

4343
#define FOSC 32000000
4444

45-
#define AO_CC1120_SPI_SPEED ao_spi_speed(6100000) /* 6.1MHz max with 32MHz osc */
45+
#define AO_CC1120_SPI_SPEED ao_spi_speed(AO_CC1120_SPI_BUS, 6100000) /* 6.1MHz max with 32MHz osc */
4646

4747
#define ao_radio_try_select(task_id) ao_spi_try_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_CC1120_SPI_SPEED, task_id)
4848
#define ao_radio_select() ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_CC1120_SPI_SPEED)

src/drivers/ao_cc115l.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static uint8_t ao_radio_abort; /* radio operation should abort */
3939

4040
#define FOSC 26000000
4141

42-
#define AO_CC115L_SPI_SPEED ao_spi_speed(6500000) /* for back-to-back access */
42+
#define AO_CC115L_SPI_SPEED ao_spi_speed(AO_CC115L_SPI_BUS, 6500000) /* for back-to-back access */
4343

4444
#define ao_radio_select() ao_spi_get_mask(AO_CC115L_SPI_CS_PORT,(1 << AO_CC115L_SPI_CS_PIN),AO_CC115L_SPI_BUS,AO_CC115L_SPI_SPEED)
4545
#define ao_radio_deselect() ao_spi_put_mask(AO_CC115L_SPI_CS_PORT,(1 << AO_CC115L_SPI_CS_PIN),AO_CC115L_SPI_BUS)

src/drivers/ao_cc1200.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extern const uint32_t ao_radio_cal;
5353
#define FOSC 40000000
5454
#endif
5555

56-
#define AO_CC1200_SPI_SPEED ao_spi_speed(7700000) /* 7.7MHz max for extended memory reads */
56+
#define AO_CC1200_SPI_SPEED ao_spi_speed(AO_CC1200_SPI_BUS, 7700000) /* 7.7MHz max for extended memory reads */
5757

5858
#define ao_radio_select() ao_spi_get_mask(AO_CC1200_SPI_CS_PORT,(1 << AO_CC1200_SPI_CS_PIN),AO_CC1200_SPI_BUS,AO_CC1200_SPI_SPEED)
5959
#define ao_radio_deselect() ao_spi_put_mask(AO_CC1200_SPI_CS_PORT,(1 << AO_CC1200_SPI_CS_PIN),AO_CC1200_SPI_BUS)

src/drivers/ao_companion.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#error HAS_COMPANION not set in ao_companion.c
2929
#endif
3030

31-
#define AO_COMPANION_SPI_SPEED ao_spi_speed(200000)
31+
#define AO_COMPANION_SPI_SPEED ao_spi_speed(AO_COMPANION_SPI_BUS, 200000)
3232

3333
#define COMPANION_SELECT() do { \
3434
ao_spi_get_bit(AO_COMPANION_CS_PORT, \

src/drivers/ao_m25.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static uint8_t ao_m25_mutex;
101101

102102
static uint8_t ao_m25_instruction[4];
103103

104-
#define AO_M25_SPI_SPEED ao_spi_speed(10000000) /* this seems like a reasonable minimum speed to require */
104+
#define AO_M25_SPI_SPEED ao_spi_speed(AO_M25_SPI_BUS, 10000000) /* this seems like a reasonable minimum speed to require */
105105

106106
#define M25_SELECT(cs) ao_spi_get_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS,AO_M25_SPI_SPEED)
107107
#define M25_DESELECT(cs) ao_spi_put_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS)

src/drivers/ao_mma655x.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define PRINTD(l,...)
3131
#endif
3232

33-
#define AO_MMA655X_SPI_SPEED ao_spi_speed(8333333) /* 120ns clock period */
33+
#define AO_MMA655X_SPI_SPEED ao_spi_speed(AO_MMA655X_SPI_INDEX, 8333333) /* 120ns clock period */
3434

3535
static void
3636
ao_mma655x_start(void) {

src/drivers/ao_mmc5983.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ao_mmc5983_raw(struct ao_mmc5983_raw *raw)
127127
#endif
128128

129129
#else
130-
#define AO_MMC5983_SPI_SPEED ao_spi_speed(2000000)
130+
#define AO_MMC5983_SPI_SPEED ao_spi_speed(AO_MMC5983_SPI_INDEX, 2000000)
131131

132132
static void
133133
ao_mmc5983_start(void) {

src/drivers/ao_mpu6000.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static uint8_t ao_mpu6000_configured;
3232

3333
#if AO_MPU6000_SPI
3434

35-
#define AO_MPU6000_SPI_SPEED ao_spi_speed(1000000) /* 1Mhz for all register access */
35+
#define AO_MPU6000_SPI_SPEED ao_spi_speed(AO_MPU6000_SPI_BUS, 1000000) /* 1Mhz for all register access */
3636

3737
#define ao_mpu6000_spi_get() ao_spi_get(AO_MPU6000_SPI_BUS, AO_MPU6000_SPI_SPEED)
3838
#define ao_mpu6000_spi_put() ao_spi_put(AO_MPU6000_SPI_BUS)

src/drivers/ao_mpu9250.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static uint8_t ao_mpu9250_configured;
3535
#if AO_MPU9250_SPI
3636

3737
#ifndef AO_MPU9250_SPI_SPEED
38-
#define AO_MPU9250_SPI_SPEED ao_spi_speed(1000000) /* 1MHz max SCLK */
38+
#define AO_MPU9250_SPI_SPEED ao_spi_speed(AO_MPU9250_SPI_BUS, 1000000) /* 1MHz max SCLK */
3939
#endif
4040

4141
#define ao_mpu9250_spi_get() ao_spi_get(AO_MPU9250_SPI_BUS, AO_MPU9250_SPI_SPEED)

src/drivers/ao_ms5607.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
struct ao_ms5607_prom ao_ms5607_prom;
2626
static uint8_t ms5607_configured;
2727

28-
#define AO_MS5607_SPI_SPEED ao_spi_speed(20000000)
28+
#define AO_MS5607_SPI_SPEED ao_spi_speed(AO_MS5607_SPI_INDEX, 20000000)
2929

3030
static void
3131
ao_ms5607_start(void) {

src/drivers/ao_st7565.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define ST7565_BOOSTER_RATIO_SET 0xf8
4848
#define ST7565_NOP 0xe3
4949

50-
#define AO_ST7565_SPI_SPEED ao_spi_speed(20000000)
50+
#define AO_ST7565_SPI_SPEED ao_spi_speed(AO_ST7565_SPI_BUS, 10000000)
5151

5252
void
5353
ao_st7565_update(struct ao_bitmap *bitmap);

src/lpc/ao_arch.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ ao_serial_init(void);
116116
#define _AO_SPI_SPEED_62500Hz 768
117117

118118
static inline uint32_t
119-
ao_spi_speed(uint32_t hz)
119+
ao_spi_speed(int index, uint32_t hz)
120120
{
121+
(void) index;
121122
if (hz >= 4000000) return _AO_SPI_SPEED_4MHz;
122123
if (hz >= 2000000) return _AO_SPI_SPEED_2MHz;
123124
if (hz >= 1000000) return _AO_SPI_SPEED_1MHz;

src/samd21/ao_arch_funcs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,11 @@ ao_spi_put_bit(struct samd21_port *port, uint8_t bit, uint16_t spi_index)
282282
}
283283

284284
static inline uint8_t
285-
ao_spi_speed(uint32_t hz)
285+
ao_spi_speed(int index, uint32_t hz)
286286
{
287287
int32_t baud = (int32_t) (AO_SYSCLK / (2 * hz)) - 1;
288288

289+
(void) index;
289290
if (baud < 1)
290291
baud = 1;
291292
if (baud > 255)

src/snekboard/snekboard.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define SNEK_CS_PORT (&samd21_port_a)
2020
#define SNEK_CS_PIN (11)
2121
#define SNEK_SPI_INDEX AO_SPI_0_PA08_PA09_PA10
22-
#define SNEK_SPI_SPEED ao_spi_speed(1000000)
22+
#define SNEK_SPI_SPEED ao_spi_speed(SNEK_SPI_INDEX, 1000000)
2323

2424
static const uint8_t spi_test[] = {
2525
0x55,

src/stm/ao_arch_funcs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
#define _AO_SPI_SPEED_62500Hz STM_SPI_CR1_BR_PCLK_256
3535

3636
static inline uint32_t
37-
ao_spi_speed(uint32_t hz)
37+
ao_spi_speed(int index, uint32_t hz)
3838
{
39+
(void) index;
3940
if (hz >= 4000000) return _AO_SPI_SPEED_4MHz;
4041
if (hz >= 2000000) return _AO_SPI_SPEED_2MHz;
4142
if (hz >= 1000000) return _AO_SPI_SPEED_1MHz;

src/stm32l0/ao_arch_funcs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
/* Companion bus wants something no faster than 200kHz */
3737

3838
static inline uint32_t
39-
ao_spi_speed(uint32_t hz)
39+
ao_spi_speed(int index, uint32_t hz)
4040
{
41+
(void) index;
4142
if (hz >= 4000000) return _AO_SPI_SPEED_4MHz;
4243
if (hz >= 2000000) return _AO_SPI_SPEED_2MHz;
4344
if (hz >= 1000000) return _AO_SPI_SPEED_1MHz;

src/stmf0/ao_arch_funcs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
#define _AO_SPI_SPEED_187500Hz STM_SPI_CR1_BR_PCLK_256
3737

3838
static inline uint32_t
39-
ao_spi_speed(uint32_t hz)
39+
ao_spi_speed(int index, uint32_t hz)
4040
{
41+
(void) index;
4142
if (hz >=24000000) return _AO_SPI_SPEED_24MHz;
4243
if (hz >=12000000) return _AO_SPI_SPEED_12MHz;
4344
if (hz >= 6000000) return _AO_SPI_SPEED_6MHz;

0 commit comments

Comments
 (0)