1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/io1_xplained: refactor implementation

- directly use underlying drivers api (gpio, at30tse75x)
- use debug instead of log + rework messages
This commit is contained in:
Alexandre Abadie 2018-04-16 16:54:37 +02:00
parent 32807bd18e
commit 4ceb309927
3 changed files with 14 additions and 58 deletions

View File

@ -81,38 +81,13 @@ typedef struct {
*
* @return IO1_XPLAINED_OK on success
* @return -IO1_XPLAINED_NOTEMP if temperature sensor initialization failed
* @return -IO1_XPLAINED_NOSDCARD if sdcard initialization failed
* @return -IO1_XPLAINED_NOLED if LED initialization failed
* @return -IO1_XPLAINED_NOGPIO1 if GPIO1 initialization failed
* @return -IO1_XPLAINED_NOGPIO2 if GPIO2 initialization failed
*/
int io1_xplained_init(io1_xplained_t *dev, const io1_xplained_params_t *params);
/**
* @brief Read temperature value from the given IO1 Xplained extension, returned in °C
*
* @param[in] dev Device descriptor of IO1 Xplained to read from
* @param[out] temperature Temperature in °C
*
* @return IO1_XPLAINED_READ_OK on success
* @return -IO1_XPLAINED_READ_ERR if temperature sensor read failed
*/
int io1_xplained_read_temperature(const io1_xplained_t *dev, float *temperature);
/**
* @brief Set the on-board led of the IO1 Xplained extension
*/
void io1_xplained_set_led(void);
/**
* @brief Clear the on-board led of the IO1 Xplained extension
*/
void io1_xplained_clear_led(void);
/**
* @brief Toggle the on-board led of the IO1 Xplained extension
*/
void io1_xplained_toggle_led(void);
#ifdef __cplusplus
}
#endif

View File

@ -18,13 +18,15 @@
* @}
*/
#include "log.h"
#include "io1_xplained.h"
#include "io1_xplained_internals.h"
#include "at30tse75x.h"
#include "periph/i2c.h"
#include "periph/gpio.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/*---------------------------------------------------------------------------*
* IO1 Xplained Core API *
*---------------------------------------------------------------------------*/
@ -36,8 +38,9 @@ int io1_xplained_init(io1_xplained_t *dev, const io1_xplained_params_t *params)
/* Initialize I2C interface */
if (at30tse75x_init(&dev->temp,
I2C_DEV(0),
I2C_SPEED_NORMAL, (TEMPERATURE_BASE_ADDR | dev->params.addr)) < 0) {
LOG_ERROR("Cannot initialize temperature sensor.\n");
I2C_SPEED_NORMAL,
(TEMPERATURE_BASE_ADDR | dev->params.addr)) < 0) {
DEBUG("[io1_xplained] Cannot initialize temperature sensor.\n");
return -IO1_XPLAINED_NOTEMP;
}
@ -45,45 +48,21 @@ int io1_xplained_init(io1_xplained_t *dev, const io1_xplained_params_t *params)
at30tse75x_set_resolution(&dev->temp, AT30TSE75X_RESOLUTION_12BIT);
if (gpio_init(IO1_LED_PIN, GPIO_OUT) < 0) {
LOG_ERROR("GPIO LED not enabled\n");
DEBUG("[io1_xplained] LED initialization failed\n");
return -IO1_XPLAINED_NOLED;
}
if (gpio_init(IO1_GPIO1_PIN, GPIO_OUT) < 0) {
LOG_ERROR("GPIO1 not enabled\n");
DEBUG("[io1_xplained] GPIO1 initialization failed\n");
return -IO1_XPLAINED_NOGPIO1;
}
if (gpio_init(IO1_GPIO2_PIN, GPIO_OUT) < 0) {
LOG_ERROR("GPIO2 not enabled\n");
DEBUG("[io1_xplained] GPIO2 initialization failed\n");
return -IO1_XPLAINED_NOGPIO2;
}
LOG_DEBUG("IO1 Xplained extension initialized!\n");
DEBUG("IO1 Xplained extension initialized with success!\n");
return IO1_XPLAINED_OK;
}
int io1_xplained_read_temperature(const io1_xplained_t *dev, float *temperature)
{
if (at30tse75x_get_temperature(&dev->temp, temperature) < 0) {
LOG_ERROR("Cannot read temperature sensor.\n");
return -IO1_XPLAINED_READ_ERR;
}
return IO1_XPLAINED_READ_OK;
}
void io1_xplained_set_led(void)
{
gpio_set(IO1_LED_PIN);
}
void io1_xplained_clear_led(void)
{
gpio_clear(IO1_LED_PIN);
}
void io1_xplained_toggle_led(void)
{
gpio_toggle(IO1_LED_PIN);
}

View File

@ -22,12 +22,14 @@
#include "saul.h"
#include "io1_xplained.h"
#include "at30tse75x.h"
static float temperature;
static int read_temperature(const void *dev, phydat_t *res)
{
io1_xplained_read_temperature((const io1_xplained_t *)dev, &temperature);
const io1_xplained_t *io1 = (const io1_xplained_t *)dev;
at30tse75x_get_temperature(&io1->temp, &temperature);
res->val[0] = (int)(temperature * 100.0);
res->unit = UNIT_TEMP_C;
res->scale = -2;