X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Favr%2Fdrv%2Fi2c_avr.c;h=a10c450dbb87bdae3eca0598c658beee4cc9c501;hb=b708b0cbae2dc58ef30943ade3d56c464b49a59c;hp=335d8330f4635722b42547b162d4f5f3d44652f8;hpb=f6a98c59209d8f21abdcb0a8411222ea4ef7c690;p=bertos.git diff --git a/bertos/cpu/avr/drv/i2c_avr.c b/bertos/cpu/avr/drv/i2c_avr.c index 335d8330..a10c450d 100644 --- a/bertos/cpu/avr/drv/i2c_avr.c +++ b/bertos/cpu/avr/drv/i2c_avr.c @@ -32,13 +32,11 @@ * * \brief Driver for the AVR ATMega TWI (implementation) * - * \version $Id$ - * * \author Stefano Fedrigo * \author Bernie Innocenti */ -#include "hw/hw_cpu.h" /* CLOCK_FREQ */ +#include /* CPU_FREQ */ #include "cfg/cfg_i2c.h" @@ -67,7 +65,7 @@ * * \return true on success, false otherwise. */ -static bool i2c_start(void) +static bool i2c_builtin_start(void) { TWCR = BV(TWINT) | BV(TWSTA) | BV(TWEN); WAIT_TWI_READY; @@ -87,7 +85,7 @@ static bool i2c_start(void) * * \return true on success, false otherwise. */ -bool i2c_start_w(uint8_t id) +bool i2c_builtin_start_w(uint8_t id) { /* * Loop on the select write sequence: when the eeprom is busy @@ -96,7 +94,7 @@ bool i2c_start_w(uint8_t id) * keep trying until the eeprom responds with an ACK. */ ticks_t start = timer_clock(); - while (i2c_start()) + while (i2c_builtin_start()) { TWDR = id & ~I2C_READBIT; TWCR = BV(TWINT) | BV(TWEN); @@ -127,9 +125,9 @@ bool i2c_start_w(uint8_t id) * * \return true on success, false otherwise. */ -bool i2c_start_r(uint8_t id) +bool i2c_builtin_start_r(uint8_t id) { - if (i2c_start()) + if (i2c_builtin_start()) { TWDR = id | I2C_READBIT; TWCR = BV(TWINT) | BV(TWEN); @@ -148,7 +146,7 @@ bool i2c_start_r(uint8_t id) /** * Send STOP condition. */ -void i2c_stop(void) +void i2c_builtin_stop(void) { TWCR = BV(TWINT) | BV(TWEN) | BV(TWSTO); } @@ -160,7 +158,7 @@ void i2c_stop(void) * * \return true on success, false on error. */ -bool i2c_put(const uint8_t data) +bool i2c_builtin_put(const uint8_t data) { TWDR = data; TWCR = BV(TWINT) | BV(TWEN); @@ -181,7 +179,7 @@ bool i2c_put(const uint8_t data) * * \return the byte read if ok, EOF on errors. */ -int i2c_get(bool ack) +int i2c_builtin_get(bool ack) { TWCR = BV(TWINT) | BV(TWEN) | (ack ? BV(TWEA) : 0); WAIT_TWI_READY; @@ -212,7 +210,7 @@ MOD_DEFINE(i2c); /** * Initialize TWI module. */ -void i2c_init(void) +void i2c_builtin_init(void) { ATOMIC( /* @@ -237,7 +235,7 @@ void i2c_init(void) /* * Set speed: - * F = CLOCK_FREQ / (16 + 2*TWBR * 4^TWPS) + * F = CPU_FREQ / (16 + 2*TWBR * 4^TWPS) */ #ifndef CONFIG_I2C_FREQ #warning Using default value of 300000L for CONFIG_I2C_FREQ @@ -245,7 +243,7 @@ void i2c_init(void) #endif #define TWI_PRESC 1 /* 4 ^ TWPS */ - TWBR = (CLOCK_FREQ / (2 * CONFIG_I2C_FREQ * TWI_PRESC)) - (8 / TWI_PRESC); + TWBR = (CPU_FREQ / (2 * CONFIG_I2C_FREQ * TWI_PRESC)) - (8 / TWI_PRESC); TWSR = 0; TWCR = BV(TWEN); );