Changed the generic functions for sensor-specific functions.

This commit is contained in:
David Žaitlík 2022-06-17 23:17:01 +02:00
parent a937c1c08b
commit 05ed8c25c9

View File

@ -5,7 +5,19 @@
* Author: david
*/
#include "ltr329.h"
#include "main.h" /* for uart_disable_interrupts() */
/*
* Functions to be implemented by user
*/
/* I2C */
int8_t ltr329_i2c_transmit(uint8_t address, uint8_t *buffer, int len) __attribute__((weak));
int8_t ltr329_i2c_receive(uint8_t address, uint8_t *buffer, int len) __attribute__((weak));
/* Interrupts */
int8_t ltr329_disable_interrupts(void) __attribute__((weak));
int8_t ltr329_enable_interrupts(void) __attribute__((weak));
/* delay function */
void delay_ms(int delay_ms) __attribute__((weak));
static int8_t ltr329_read_register (ltr329_cmd_t register_addr, uint8_t *register_data )
{
@ -16,17 +28,17 @@ static int8_t ltr329_read_register (ltr329_cmd_t register_addr, uint8_t *registe
// start measurement
tx_buffer[0] = register_addr;
/* disable interrupts to prevent modbus/i2c conflict */
uart_disable_interrupts();
result = i2c_transmit(LTR329_I2C_ADDRESS<<1, tx_buffer, 1);
uart_enable_interrupts();
ltr329_disable_interrupts();
result = ltr329_i2c_transmit(LTR329_I2C_ADDRESS<<1, tx_buffer, 1);
ltr329_enable_interrupts();
if (result != I2C_OK) {
return LTR329_ERROR;
}
LL_mDelay(10); /* 10 ms should be enough */
delay_ms(10); /* 10 ms should be enough */
/* read out */
uart_disable_interrupts();
result = i2c_receive(LTR329_I2C_ADDRESS<<1, rx_buffer, 1);
uart_enable_interrupts();
ltr329_disable_interrupts();
result = ltr329_i2c_receive(LTR329_I2C_ADDRESS<<1, rx_buffer, 1);
ltr329_enable_interrupts();
if (result != I2C_OK) {
return LTR329_ERROR;
}
@ -44,9 +56,9 @@ static int8_t ltr329_write_register (ltr329_cmd_t register_addr, uint8_t registe
tx_buffer[0] = register_addr;
tx_buffer[1] = register_data;
/* disable interrupts to prevent modbus/i2c conflict */
uart_disable_interrupts();
result = i2c_transmit(LTR329_I2C_ADDRESS<<1, tx_buffer, 2);
uart_enable_interrupts();
ltr329_disable_interrupts();
result = ltr329_i2c_transmit(LTR329_I2C_ADDRESS<<1, tx_buffer, 2);
ltr329_enable_interrupts();
if (result != I2C_OK) {
return LTR329_ERROR;
}