Skip to content

Commit

Permalink
ism330dlc: added const to stmdev_write_ptr #121
Browse files Browse the repository at this point in the history
  • Loading branch information
albezanc committed May 21, 2021
1 parent 5a4d9da commit f62cb9f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ism330dlc_STdC/driver
15 changes: 7 additions & 8 deletions ism330dlc_STdC/examples/ism330dlc_read_data_polling.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/

//#define STEVAL_MKI109V3 /* little endian */
#define NUCLEO_F411RE /* little endian */
//#define NUCLEO_F411RE /* little endian */
//#define SPC584B_DIS /* big endian */

/* ATTENTION: By default the driver is little endian. If you need switch
Expand Down Expand Up @@ -92,6 +92,7 @@
#include "usbd_cdc_if.h"
#include "gpio.h"
#include "spi.h"
#include "tim.h"

#elif defined(SPC584B_DIS)
#include "components.h"
Expand Down Expand Up @@ -120,8 +121,7 @@ static uint8_t tx_buffer[TX_BUF_DIM];
* and are strictly related to the hardware platform used.
*
*/
static int32_t platform_write(void *handle, uint8_t reg,
uint8_t *bufp,
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
uint16_t len);
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
uint16_t len);
Expand Down Expand Up @@ -238,20 +238,19 @@ void ism330dlc_read_data_polling(void)
* @param len number of consecutive register to write
*
*/
static int32_t platform_write(void *handle, uint8_t reg,
uint8_t *bufp,
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
uint16_t len)
{
#if defined(NUCLEO_F411RE)
HAL_I2C_Mem_Write(handle, ISM330DLC_I2C_ADD_L, reg,
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);
#elif defined(STEVAL_MKI109V3)
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, &reg, 1, 1000);
HAL_SPI_Transmit(handle, bufp, len, 1000);
HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
#elif defined(SPC584B_DIS)
i2c_lld_write(handle, ISM330DLC_I2C_ADD_L & 0xFE, reg, bufp, len);
i2c_lld_write(handle, ISM330DLC_I2C_ADD_L & 0xFE, reg, (uint8_t*) bufp, len);
#endif
return 0;
}
Expand Down
71 changes: 33 additions & 38 deletions ism330dlc_STdC/examples/ism330dlc_self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/

//#define STEVAL_MKI109V3 /* little endian */
#define NUCLEO_F411RE /* little endian */
//#define NUCLEO_F411RE /* little endian */
//#define SPC584B_DIS /* big endian */

/* ATTENTION: By default the driver is little endian. If you need switch
Expand Down Expand Up @@ -93,6 +93,7 @@
#include "usbd_cdc_if.h"
#include "gpio.h"
#include "spi.h"
#include "tim.h"

#elif defined(SPC584B_DIS)
#include "components.h"
Expand Down Expand Up @@ -127,8 +128,7 @@
* and are strictly related to the hardware platform used.
*
*/
static int32_t platform_write(void *handle, uint8_t reg,
uint8_t *bufp,
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
uint16_t len);
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
uint16_t len);
Expand Down Expand Up @@ -372,24 +372,19 @@ void ism330dlc_self_test(void)
* @param len number of consecutive register to write
*
*/
static int32_t platform_write(void *handle, uint8_t reg,
uint8_t *bufp,
static int32_t platform_write(void *handle, uint8_t reg, const uint8_t *bufp,
uint16_t len)
{
if (handle == &hi2c1) {
HAL_I2C_Mem_Write(handle, ISM330DLC_I2C_ADD_L, reg,
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
}

#ifdef STEVAL_MKI109V3

else if (handle == &hspi2) {
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, &reg, 1, 1000);
HAL_SPI_Transmit(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
}

#if defined(NUCLEO_F411RE)
HAL_I2C_Mem_Write(handle, ISM330DLC_I2C_ADD_L, reg,
I2C_MEMADD_SIZE_8BIT, (uint8_t*) bufp, len, 1000);
#elif defined(STEVAL_MKI109V3)
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, &reg, 1, 1000);
HAL_SPI_Transmit(handle, (uint8_t*) bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
#elif defined(SPC584B_DIS)
i2c_lld_write(handle, ISM330DLC_I2C_ADD_L & 0xFE, reg, (uint8_t*) bufp, len);
#endif
return 0;
}
Expand All @@ -407,22 +402,17 @@ static int32_t platform_write(void *handle, uint8_t reg,
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
uint16_t len)
{
if (handle == &hi2c1) {
HAL_I2C_Mem_Read(handle, ISM330DLC_I2C_ADD_L, reg,
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
}

#ifdef STEVAL_MKI109V3

else if (handle == &hspi2) {
/* Read command */
reg |= 0x80;
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, &reg, 1, 1000);
HAL_SPI_Receive(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
}

#if defined(NUCLEO_F411RE)
HAL_I2C_Mem_Read(handle, ISM330DLC_I2C_ADD_L, reg,
I2C_MEMADD_SIZE_8BIT, bufp, len, 1000);
#elif defined(STEVAL_MKI109V3)
reg |= 0x80;
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, &reg, 1, 1000);
HAL_SPI_Receive(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
#elif defined(SPC584B_DIS)
i2c_lld_read(handle, ISM330DLC_I2C_ADD_L & 0xFE, reg, bufp, len);
#endif
return 0;
}
Expand All @@ -436,11 +426,12 @@ static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
*/
static void tx_com(uint8_t *tx_buffer, uint16_t len)
{
#ifdef NUCLEO_F411RE
#if defined(NUCLEO_F411RE)
HAL_UART_Transmit(&huart2, tx_buffer, len, 1000);
#endif
#ifdef STEVAL_MKI109V3
#elif defined(STEVAL_MKI109V3)
CDC_Transmit_FS(tx_buffer, len);
#elif defined(SPC584B_DIS)
sd_lld_write(&SD2, tx_buffer, len);
#endif
}

Expand All @@ -452,7 +443,11 @@ static void tx_com(uint8_t *tx_buffer, uint16_t len)
*/
static void platform_delay(uint32_t ms)
{
#if defined(NUCLEO_F411RE) | defined(STEVAL_MKI109V3)
HAL_Delay(ms);
#elif defined(SPC584B_DIS)
osalThreadDelayMilliseconds(ms);
#endif
}

/*
Expand Down

0 comments on commit f62cb9f

Please sign in to comment.