#include <drv/ntc.h> // Macro and data type to manage celsius degree
#define SELECT_ADDRESS(addr) LM75_ADDRESS_BYTE | (addr << 1)
+#define LM75_ADDRESS_BYTE 0x91
+#define LM75_PAD_BYTE 0x0
-deg_t lm75_read(uint8_t sens_addr)
+deg_t lm75_read_1(uint8_t sens_addr)
{
uint8_t data[2];
int16_t degree;
return degree * 10 + deci_degree;
}
-void lm75_init(void)
+void lm75_init_0(void)
{
// Check dependence
MOD_CHECK(i2c);
LM75_HW_INIT();
}
+/*
+ * New API
+ */
+deg_t lm75_read_2(I2c *i2c, uint8_t sens_addr)
+{
+ uint8_t data[2];
+ int16_t degree;
+ int16_t deci_degree;
+
+ i2c_start_w(i2c, SELECT_ADDRESS(sens_addr), 1, I2C_NOSTOP);
+ i2c_putc(i2c, LM75_PAD_BYTE);
+ i2c_start_r(i2c, SELECT_ADDRESS(sens_addr), sizeof(data), I2C_STOP);
+ i2c_read(i2c, data, sizeof(data));
+
+ if (i2c_error(i2c))
+ return EOF;
+
+ degree = (int16_t)data[0];
+ deci_degree = (int16_t)(((data[1] >> 7) & 1 ) * 5);
+ LOG_INFO("[%d.%d C]\n", degree, deci_degree);
+
+ return degree * 10 + deci_degree;
+}
+
+void lm75_init_1(I2c *i2c)
+{
+ ASSERT(i2c);
+
+ // Check dependence
+ LM75_HW_INIT();
+}
#include <cpu/types.h>
#include <drv/ntc.h> // Macro and data type to manage celsius degree
+#include <drv/i2c.h>
-#define LM75_ADDRESS_BYTE 0x91
-#define LM75_PAD_BYTE 0x0
+#include <cpu/attr.h>
-deg_t lm75_read(uint8_t sens_addr);
+#define I2C_READBIT BV(0)
-void lm75_init(void);
+#if COMPILER_C99
+ #define lm75_init(...) PP_CAT(lm75_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+ #define lm75_read(...) PP_CAT(lm75_read ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+#else
+ #define lm75_init(args...) PP_CAT(lm75_init ## _, COUNT_PARMS(args)) (args)
+ #define lm75_read(args...) PP_CAT(lm75_read ## _, COUNT_PARMS(args)) (args)
+#endif
+
+DEPRECATED deg_t lm75_read_1(uint8_t sens_addr);
+DEPRECATED void lm75_init_0(void);
+
+deg_t lm75_read_2(I2c *i2c, uint8_t sens_addr);
+void lm75_init_1(I2c *i2c);
#endif /* DRV_LM75_H */
*/
#include "pcf8574.h"
+
#include <cfg/module.h>
+
#include <drv/i2c.h>
/**
* Read PCF8574 \a pcf bit status.
* \return the pins status or EOF on errors.
*/
-int pcf8574_get(Pcf8574 *pcf)
+int pcf8574_get_1(Pcf8574 *pcf)
{
if (!i2c_start_r(PCF8574ID | ((pcf->addr << 1) & 0xF7)))
return EOF;
- int data;
-
+ int data;
+
if (!i2c_recv(&data, 1))
data = EOF;
-
+
i2c_stop();
-
+
return data;
}
* Write to PCF8574 \a pcf port \a data.
* \return true if ok, false on errors.
*/
-bool pcf8574_put(Pcf8574 *pcf, uint8_t data)
+bool pcf8574_put_2(Pcf8574 *pcf, uint8_t data)
{
bool res = i2c_start_w(PCF8574ID | ((pcf->addr << 1) & 0xF7)) && i2c_put(data);
i2c_stop();
* Init a PCF8574 on the bus with addr \a addr.
* \return true if device is found, false otherwise.
*/
-bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr)
+bool pcf8574_init_2(Pcf8574 *pcf, pcf8574_addr addr)
{
MOD_CHECK(i2c);
pcf->addr = addr;
return pcf8574_get(pcf) != EOF;
}
+
+
+
+/*
+ * New API
+ */
+
+/**
+ * Read PCF8574 \a pcf bit status.
+ * \return the pins status or EOF on errors.
+ */
+int pcf8574_get_2(I2c *i2c, Pcf8574 *pcf)
+{
+ i2c_start_r(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
+
+ int data = i2c_getc(i2c);
+
+ if (i2c_error(i2c))
+ data = EOF;
+
+ return data;
+}
+
+/**
+ * Write to PCF8574 \a pcf port \a data.
+ * \return true if ok, false on errors.
+ */
+bool pcf8574_put_3(I2c *i2c, Pcf8574 *pcf, uint8_t data)
+{
+ i2c_start_w(i2c, PCF8574ID | ((pcf->addr << 1) & 0xF7), 1, I2C_STOP);
+ i2c_putc(i2c, data);
+
+ if (i2c_error(i2c))
+ return false;
+
+ return true;
+}
+
+/**
+ * Init a PCF8574 on the bus with addr \a addr.
+ * \return true if device is found, false otherwise.
+ */
+bool pcf8574_init_3(I2c *i2c, Pcf8574 *pcf, pcf8574_addr addr)
+{
+ ASSERT(i2c);
+ pcf->addr = addr;
+
+ return (pcf8574_get(i2c, pcf) != EOF);
+}
+
#include <cfg/compiler.h>
+#include <drv/i2c.h>
+
+#if COMPILER_C99
+ #define pcf8574_init(...) PP_CAT(pcf8574_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+ #define pcf8574_get(...) PP_CAT(pcf8574_get ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+ #define pcf8574_put(...) PP_CAT(pcf8574_put ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+#else
+ #define pcf8574_init(args...) PP_CAT(pcf8574_init ## _, COUNT_PARMS(args)) (args)
+ #define pcf8574_get(args...) PP_CAT(pcf8574_get ## _, COUNT_PARMS(args)) (args)
+ #define pcf8574_put(args...) PP_CAT(pcf8574_put ## _, COUNT_PARMS(args)) (args)
+#endif
+
typedef uint8_t pcf8574_addr;
/**
#define PCF8574ID 0x40 ///< I2C address
-int pcf8574_get(Pcf8574 *pcf);
-bool pcf8574_put(Pcf8574 *pcf, uint8_t data);
-bool pcf8574_init(Pcf8574 *pcf, pcf8574_addr addr);
+DEPRECATED int pcf8574_get_1(Pcf8574 *pcf);
+DEPRECATED bool pcf8574_put_2(Pcf8574 *pcf, uint8_t data);
+DEPRECATED bool pcf8574_init_2(Pcf8574 *pcf, pcf8574_addr addr);
+
+
+int pcf8574_get_2(I2c *i2c, Pcf8574 *pcf);
+bool pcf8574_put_3(I2c *i2c, Pcf8574 *pcf, uint8_t data);
+bool pcf8574_init_3(I2c *i2c, Pcf8574 *pcf, pcf8574_addr addr);
#endif /* DRV_PCF8574_H */
#include <drv/i2c.h>
#include <drv/timer.h>
+typedef uint8_t tas_addr_t;
#define TAS_ADDR 0x36
-typedef uint8_t tas_addr_t;
+#define TRIM_REG 0x1B
+#define SYS_REG2 0x05
+#define VOLUME_REG 0x07
+#define MUTE_VOL 0xFF
+
+#define DB_TO_REG(db) ((24 - (db)) * 2)
+
+#define CH1_VOL_REG 0x08
+#define CH2_VOL_REG 0x09
+#define CH3_VOL_REG 0x0A
+#define CH4_VOL_REG 0x0B
static bool tas5706a_send(tas_addr_t addr, const void *buf, size_t len)
{
return ret;
}
-INLINE bool tas5706a_putc(tas_addr_t addr, uint8_t ch)
+INLINE bool tas5706a_put(tas_addr_t addr, uint8_t ch)
{
return tas5706a_send(addr, &ch, sizeof(ch));
}
return ret;
}
-INLINE int tas5706a_getc(tas_addr_t addr)
+INLINE int tas5706a_get(tas_addr_t addr)
{
uint8_t ch;
if (tas5706a_recv(addr, &ch, sizeof(ch)))
return EOF;
}
-#define TRIM_REG 0x1B
-#define SYS_REG2 0x05
-#define VOLUME_REG 0x07
-#define MUTE_VOL 0xFF
-
-#define DB_TO_REG(db) ((24 - (db)) * 2)
-
-void tas5706a_init(void)
+void tas5706a_init_0(void)
{
MOD_CHECK(i2c);
MOD_CHECK(timer);
timer_delay(2);
TAS5706A_SETRESET(false);
timer_delay(20);
- tas5706a_putc(TRIM_REG, 0x00);
+ tas5706a_put(TRIM_REG, 0x00);
- tas5706a_putc(VOLUME_REG, DB_TO_REG(CONFIG_TAS_MAX_VOL));
+ tas5706a_put(VOLUME_REG, DB_TO_REG(CONFIG_TAS_MAX_VOL));
/* Unmute */
- tas5706a_putc(SYS_REG2, 0);
+ tas5706a_put(SYS_REG2, 0);
}
-#define CH1_VOL_REG 0x08
-#define CH2_VOL_REG 0x09
-#define CH3_VOL_REG 0x0A
-#define CH4_VOL_REG 0x0B
+void tas5706a_setVolume_2(Tas5706aCh ch, tas5706a_vol_t vol)
+{
+ ASSERT(ch < TAS_CNT);
+ ASSERT(vol <= TAS_VOL_MAX);
-void tas5706a_setVolume(Tas5706aCh ch, tas5706a_vol_t vol)
+ tas_addr_t addr1, addr2;
+
+ switch(ch)
+ {
+ case TAS_CH1:
+ addr1 = CH1_VOL_REG;
+ addr2 = CH3_VOL_REG;
+ break;
+ case TAS_CH2:
+ addr1 = CH2_VOL_REG;
+ addr2 = CH4_VOL_REG;
+ break;
+ default:
+ ASSERT(0);
+ return;
+ }
+
+ uint8_t vol_att = 0xff - ((vol * 0xff) / TAS_VOL_MAX);
+
+ tas5706a_put(addr1, vol_att);
+ tas5706a_put(addr2, vol_att);
+}
+
+void tas5706a_setLowPower_1(bool val)
+{
+ TAS5706A_SETPOWERDOWN(val);
+ TAS5706A_SETMUTE(val);
+}
+
+/*
+ * New API
+ */
+
+INLINE bool tas5706a_putc(I2c *i2c, tas_addr_t addr, uint8_t ch)
+{
+ i2c_start_w(i2c, TAS_ADDR, 2, I2C_STOP);
+ i2c_putc(i2c, addr);
+ i2c_putc(i2c, ch);
+
+ if (i2c_error(i2c))
+ return false;
+
+ return true;
+}
+
+void tas5706a_setVolume_3(I2c *i2c, Tas5706aCh ch, tas5706a_vol_t vol)
{
ASSERT(ch < TAS_CNT);
ASSERT(vol <= TAS_VOL_MAX);
uint8_t vol_att = 0xff - ((vol * 0xff) / TAS_VOL_MAX);
- tas5706a_putc(addr1, vol_att);
- tas5706a_putc(addr2, vol_att);
+ tas5706a_putc(i2c, addr1, vol_att);
+ tas5706a_putc(i2c, addr2, vol_att);
}
-void tas5706a_setLowPower(bool val)
+void tas5706a_setLowPower_2(I2c *i2c, bool val)
{
+ ASSERT(i2c);
+
TAS5706A_SETPOWERDOWN(val);
TAS5706A_SETMUTE(val);
}
+
+void tas5706a_init_1(I2c *i2c)
+{
+ ASSERT(i2c);
+ MOD_CHECK(timer);
+
+ TAS5706A_PIN_INIT();
+ timer_delay(200);
+ TAS5706A_SETPOWERDOWN(false);
+ TAS5706A_SETMUTE(false);
+ TAS5706A_MCLK_INIT();
+ timer_delay(2);
+ TAS5706A_SETRESET(false);
+ timer_delay(20);
+ tas5706a_putc(i2c, TRIM_REG, 0x00);
+
+ tas5706a_putc(i2c, VOLUME_REG, DB_TO_REG(CONFIG_TAS_MAX_VOL));
+
+ /* Unmute */
+ tas5706a_putc(i2c, SYS_REG2, 0);
+}
#include <cfg/compiler.h>
+#include <drv/i2c.h>
+
+#if COMPILER_C99
+ #define tas5706a_init(...) PP_CAT(tas5706a_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+ #define tas5706a_setLowPower(...) PP_CAT(tas5706a_setLowPower ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+ #define tas5706a_setVolume(...) PP_CAT(tas5706a_setVolume ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__)
+#else
+ #define tas5706a_init(args...) PP_CAT(tas5706a_init ## _, COUNT_PARMS(args)) (args)
+ #define tas5706a_setLowPower(args...) PP_CAT(tas5706a_setLowPower ## _, COUNT_PARMS(args)) (args)
+ #define tas5706a_setVolume(args...) PP_CAT(tas5706a_setVolume ## _, COUNT_PARMS(args)) (args)
+#endif
+
typedef enum Tas5706aCh
{
TAS_CH1,
* \param ch The channel to be controlled.
* \param vol The volume you want to set.
*/
-void tas5706a_setVolume(Tas5706aCh ch, tas5706a_vol_t vol);
-
-/**
- * Initialize the TAS chip.
- */
-void tas5706a_init(void);
+void tas5706a_setVolume_3(I2c *i2c, Tas5706aCh ch, tas5706a_vol_t vol);
/**
* Set TAS chip to low power mode.
*
* \param val True if you want to enable low power mode, false otherwise.
*/
-void tas5706a_setLowPower(bool val);
+void tas5706a_setLowPower_2(I2c *i2c, bool val);
+
+/**
+ * Initialize the TAS chip.
+ */
+void tas5706a_init_1(I2c *i2c);
+
+
+DEPRECATED void tas5706a_setVolume_2(Tas5706aCh ch, tas5706a_vol_t vol);
+DEPRECATED void tas5706a_setLowPower_1(bool val);
+DEPRECATED void tas5706a_init_0(void);
#endif /* DRV_TAS5706A_H */