Commit 63b3e0b4 authored by Guillaume Gonnet's avatar Guillaume Gonnet
Browse files

Add DS75LX temperature driver.

parent d9cf54dd
......@@ -50,6 +50,7 @@ USEMODULE += $(DRIVER)
USEMODULE += random
USEMODULE += periph_eeprom
USEMODULE += periph_uart
USEMODULE += periph_i2c
# Source directory is "src".
......
/*
Driver for the DS75LX digital thermometer.
Copyright (C) 2019, ENSIMAG students
This file is based on DS75LX module from IBM LMIC, under Eclipse Public License
v1.0.
*/
#include "ds75lx.h"
#define ENABLE_DEBUG (1)
#include <debug.h>
// I2C registers.
#define TEMP_REG 0x00 // Temperature register.
#define CONFIG_REG 0x01 // Configuration register.
// Masks to extract the concerned bits.
#define MASK_RESOLUTION 0x60 // 0b01100000
// Debug an I2C result.
#define DS75_DEBUG(text, res) \
if ((res) != 0) DEBUG("[ds75]" text ": %i\n", (res));
// Initialize DS75LX module.
uint8_t ds75_init(void)
{
i2c_acquire(DS75_I2C_DEV);
int res = i2c_write_reg(DS75_I2C_DEV, DS75_I2C_ADDRESS, CONFIG_REG, DS75_RES9, 0);
i2c_release(DS75_I2C_DEV);
DS75_DEBUG("initialize error", res);
return res;
}
// Set the resolution of DS75LX chip.
uint8_t ds75_set_resolution(uint8_t resol)
{
uint8_t config;
i2c_acquire(DS75_I2C_DEV);
int res = i2c_read_reg(DS75_I2C_DEV, DS75_I2C_ADDRESS, CONFIG_REG, &config, 0);
DS75_DEBUG("read config error", res);
config &= ~MASK_RESOLUTION;
config |= resol;
res = i2c_write_reg(DS75_I2C_DEV, DS75_I2C_ADDRESS, CONFIG_REG, DS75_RES9, 0);
i2c_release(DS75_I2C_DEV);
DS75_DEBUG("set resolution error", res);
return res;
}
// Read temperature from DS75LX chip.
uint8_t ds75_read_temperature(uint16_t *temp)
{
uint8_t buffer[2];
i2c_acquire(DS75_I2C_DEV);
int res = i2c_read_regs(DS75_I2C_DEV, DS75_I2C_ADDRESS, TEMP_REG, buffer, 2, 0);
i2c_release(DS75_I2C_DEV);
*temp = (buffer[0] << 8) | buffer[1];
DS75_DEBUG("read temp error", res);
return res;
}
......@@ -3,9 +3,50 @@
Driver for the DS75LX digital thermometer.
Copyright (C) 2019, ENSIMAG students
This file is based on DS75LX module from IBM LMIC, under Eclipse Public License
v1.0.
This project is under the MIT license
*/
#pragma once
#include <periph/i2c.h>
// Return codes.
#define DS75_SUCCESS 0
#define DS75_FAIL 1
// Default device to use.
#define DS75_I2C_DEV (I2C_DEV(0))
// Default I2C address to use.
#define DS75_I2C_ADDRESS (0x68)
// DS75LX resolution.
#define DS75_RES9 0x00
#define DS75_RES10 0x20
#define DS75_RES11 0x40
#define DS75_RES12 0x60
/**
* @brief Initialize DS75LX module.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t ds75_init(void);
/**
* @brief Set the resolution of DS75LX chip.
* @param resol The resolution to use.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t ds75_set_resolution(uint8_t resol);
/**
* @brief Read temperature from DS75LX chip.
* @param temp Where to store the result.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t ds75_read_temperature(uint16_t *temp);
......@@ -3,7 +3,7 @@
Decode GPS data.
Copyright (C) 2019, ENSIMAG students
This file is based on LoRaMAC-node from Semtech, under Revised BSD License.
This project is under the MIT license
*/
......
......@@ -8,6 +8,7 @@ This project is under the MIT license
*/
#include "lorariot.h"
#include "drivers/ds75lx.h"
#include "providers/providers.h"
#include "commands/commands.h"
......@@ -18,6 +19,7 @@ This project is under the MIT license
int main(void)
{
lorariot_init();
ds75_init();
cmds_init();
#if RESET_ON_START
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment