Skip to content

Commit cf4fe12

Browse files
author
albezanc
committed
lps22hb: added const to stmdev_write_ptr #121
1 parent 434e79e commit cf4fe12

4 files changed

Lines changed: 26 additions & 29 deletions

File tree

lps22hb_STdC/driver

lps22hb_STdC/examples/lps22hb_multi_read_fifo.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454

5555
//#define STEVAL_MKI109V3 /* little endian */
56-
#define NUCLEO_F411RE /* little endian */
56+
//#define NUCLEO_F411RE /* little endian */
5757
//#define SPC584B_DIS /* big endian */
5858

5959
/* ATTENTION: By default the driver is little endian. If you need switch
@@ -93,6 +93,7 @@
9393
#include "usbd_cdc_if.h"
9494
#include "gpio.h"
9595
#include "spi.h"
96+
#include "tim.h"
9697

9798
#elif defined(SPC584B_DIS)
9899
#include "components.h"
@@ -118,8 +119,7 @@ static stmdev_ctx_t dev_ctx;
118119
* and are strictly related to the hardware platform used.
119120
*
120121
*/
121-
static int32_t platform_write(void *handle, uint8_t reg,
122-
uint8_t *bufp,
122+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
123123
uint16_t len);
124124
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
125125
uint16_t len);
@@ -201,20 +201,19 @@ void lps22hb_multi_read_fifo(void)
201201
* @param len number of consecutive register to write
202202
*
203203
*/
204-
static int32_t platform_write(void *handle, uint8_t reg,
205-
uint8_t *bufp,
204+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
206205
uint16_t len)
207206
{
208207
#if defined(NUCLEO_F411RE)
209208
HAL_I2C_Mem_Write(handle, LPS22HB_I2C_ADD_H, reg,
210-
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
209+
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);
211210
#elif defined(STEVAL_MKI109V3)
212211
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
213212
HAL_SPI_Transmit(handle, &reg, 1, 1000);
214-
HAL_SPI_Transmit(handle, bufp, len, 1000);
213+
HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);
215214
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
216215
#elif defined(SPC584B_DIS)
217-
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, bufp, len);
216+
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);
218217
#endif
219218
return 0;
220219
}
@@ -290,7 +289,7 @@ static void platform_init(void)
290289
TIM3->CCR2 = PWM_3V3;
291290
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
292291
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
293-
HAL_Delay(1000);
292+
platform_delay(1000);
294293
#endif
295294
}
296295

lps22hb_STdC/examples/lps22hb_read_data_polling.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454

5555
//#define STEVAL_MKI109V3 /* little endian */
56-
#define NUCLEO_F411RE /* little endian */
56+
//#define NUCLEO_F411RE /* little endian */
5757
//#define SPC584B_DIS /* big endian */
5858

5959
/* ATTENTION: By default the driver is little endian. If you need switch
@@ -93,6 +93,7 @@
9393
#include "usbd_cdc_if.h"
9494
#include "gpio.h"
9595
#include "spi.h"
96+
#include "tim.h"
9697

9798
#elif defined(SPC584B_DIS)
9899
#include "components.h"
@@ -118,8 +119,7 @@ static stmdev_ctx_t dev_ctx;
118119
* and are strictly related to the hardware platform used.
119120
*
120121
*/
121-
static int32_t platform_write(void *handle, uint8_t reg,
122-
uint8_t *bufp,
122+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
123123
uint16_t len);
124124
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
125125
uint16_t len);
@@ -190,20 +190,19 @@ void lps22hb_read_data_polling(void)
190190
* @param len number of consecutive register to write
191191
*
192192
*/
193-
static int32_t platform_write(void *handle, uint8_t reg,
194-
uint8_t *bufp,
193+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
195194
uint16_t len)
196195
{
197196
#if defined(NUCLEO_F411RE)
198197
HAL_I2C_Mem_Write(handle, LPS22HB_I2C_ADD_H, reg,
199-
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
198+
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);
200199
#elif defined(STEVAL_MKI109V3)
201200
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
202201
HAL_SPI_Transmit(handle, &reg, 1, 1000);
203-
HAL_SPI_Transmit(handle, bufp, len, 1000);
202+
HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);
204203
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
205204
#elif defined(SPC584B_DIS)
206-
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, bufp, len);
205+
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);
207206
#endif
208207
return 0;
209208
}
@@ -279,7 +278,7 @@ static void platform_init(void)
279278
TIM3->CCR2 = PWM_3V3;
280279
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
281280
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
282-
HAL_Delay(1000);
281+
platform_delay(1000);
283282
#endif
284283
}
285284

lps22hb_STdC/examples/lps22hb_read_one_shot.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454

5555
//#define STEVAL_MKI109V3 /* little endian */
56-
#define NUCLEO_F411RE /* little endian */
56+
//#define NUCLEO_F411RE /* little endian */
5757
//#define SPC584B_DIS /* big endian */
5858

5959
/* ATTENTION: By default the driver is little endian. If you need switch
@@ -93,6 +93,7 @@
9393
#include "usbd_cdc_if.h"
9494
#include "gpio.h"
9595
#include "spi.h"
96+
#include "tim.h"
9697

9798
#elif defined(SPC584B_DIS)
9899
#include "components.h"
@@ -118,8 +119,7 @@ static stmdev_ctx_t dev_ctx;
118119
* and are strictly related to the hardware platform used.
119120
*
120121
*/
121-
static int32_t platform_write(void *handle, uint8_t reg,
122-
uint8_t *bufp,
122+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
123123
uint16_t len);
124124
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
125125
uint16_t len);
@@ -132,7 +132,7 @@ void lps22hb_read_one_shot(void)
132132
/* Initialize mems driver interface */
133133
dev_ctx.write_reg = platform_write;
134134
dev_ctx.read_reg = platform_read;
135-
dev_ctx.handle = &hi2c1;
135+
dev_ctx.handle = &SENSOR_BUS;
136136
/* Initialize platform specific hardware */
137137
platform_init();
138138
/* Check device ID */
@@ -195,20 +195,19 @@ void lps22hb_read_one_shot(void)
195195
* @param len number of consecutive register to write
196196
*
197197
*/
198-
static int32_t platform_write(void *handle, uint8_t reg,
199-
uint8_t *bufp,
198+
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
200199
uint16_t len)
201200
{
202201
#if defined(NUCLEO_F411RE)
203202
HAL_I2C_Mem_Write(handle, LPS22HB_I2C_ADD_H, reg,
204-
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
203+
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);
205204
#elif defined(STEVAL_MKI109V3)
206205
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
207206
HAL_SPI_Transmit(handle, &reg, 1, 1000);
208-
HAL_SPI_Transmit(handle, bufp, len, 1000);
207+
HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);
209208
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
210209
#elif defined(SPC584B_DIS)
211-
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, bufp, len);
210+
i2c_lld_write(handle, LPS22HB_I2C_ADD_H & 0xFE, reg, (uint8_t*) bufp, len);
212211
#endif
213212
return 0;
214213
}
@@ -284,7 +283,7 @@ static void platform_init(void)
284283
TIM3->CCR2 = PWM_3V3;
285284
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
286285
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
287-
HAL_Delay(1000);
286+
platform_delay(1000);
288287
#endif
289288
}
290289

0 commit comments

Comments
 (0)