From 914025973de120a011aa8f328205fb816a716a02 Mon Sep 17 00:00:00 2001 From: Robert Hartung Date: Thu, 14 Sep 2017 10:35:06 +0200 Subject: [PATCH] cpu/atmega: use power.h defines instead of direct register access --- boards/arduino-atmega-common/include/periph_conf.h | 8 -------- boards/waspmote-pro/include/periph_conf.h | 1 - cpu/atmega1281/include/periph_cpu.h | 1 - cpu/atmega2560/include/periph_cpu.h | 1 - cpu/atmega328p/include/periph_cpu.h | 1 - cpu/atmega_common/include/atmega_regs_common.h | 1 + cpu/atmega_common/periph/i2c.c | 4 ++-- cpu/atmega_common/periph/spi.c | 7 +++---- 8 files changed, 6 insertions(+), 18 deletions(-) diff --git a/boards/arduino-atmega-common/include/periph_conf.h b/boards/arduino-atmega-common/include/periph_conf.h index 71b6903693..af5e5bdcbe 100644 --- a/boards/arduino-atmega-common/include/periph_conf.h +++ b/boards/arduino-atmega-common/include/periph_conf.h @@ -133,14 +133,6 @@ extern "C" { * @{ */ #define SPI_NUMOF 1 /* set to 0 to disable SPI */ - -#ifdef CPU_ATMEGA328P -#define MEGA_PRR PRR /* Power Reduction Register is PRR */ -#endif - -#ifdef CPU_ATMEGA2560 -#define MEGA_PRR PRR0 /* Power Reduction Register is PRR0 */ -#endif /** @} */ /** diff --git a/boards/waspmote-pro/include/periph_conf.h b/boards/waspmote-pro/include/periph_conf.h index 0caa7548cf..8c2476c53d 100644 --- a/boards/waspmote-pro/include/periph_conf.h +++ b/boards/waspmote-pro/include/periph_conf.h @@ -101,7 +101,6 @@ extern "C" { * @{ */ #define SPI_NUMOF 1 /* set to 0 to disable SPI */ -#define MEGA_PRR PRR0 /* Power Reduction Register */ /** @} */ /** diff --git a/cpu/atmega1281/include/periph_cpu.h b/cpu/atmega1281/include/periph_cpu.h index 3d74de0ec4..1f503fdb07 100644 --- a/cpu/atmega1281/include/periph_cpu.h +++ b/cpu/atmega1281/include/periph_cpu.h @@ -48,7 +48,6 @@ enum { */ #define I2C_PORT_REG PORTD #define I2C_PIN_MASK (1 << PORTD0) | (1 << PORTD1) -#define I2C_POWER_REG PRR0 /** @} */ #ifdef __cplusplus diff --git a/cpu/atmega2560/include/periph_cpu.h b/cpu/atmega2560/include/periph_cpu.h index 83257818d6..92fd809686 100644 --- a/cpu/atmega2560/include/periph_cpu.h +++ b/cpu/atmega2560/include/periph_cpu.h @@ -50,7 +50,6 @@ enum { */ #define I2C_PORT_REG PORTD #define I2C_PIN_MASK (1 << PORTD0) | (1 << PORTD1) -#define I2C_POWER_REG PRR0 /** @} */ #ifdef __cplusplus diff --git a/cpu/atmega328p/include/periph_cpu.h b/cpu/atmega328p/include/periph_cpu.h index 7ee09fe0bf..5e29096ad4 100644 --- a/cpu/atmega328p/include/periph_cpu.h +++ b/cpu/atmega328p/include/periph_cpu.h @@ -47,7 +47,6 @@ enum { */ #define I2C_PORT_REG PORTC #define I2C_PIN_MASK (1 << PORTC4) | (1 << PORTC5) -#define I2C_POWER_REG PRR /** @} */ #ifdef __cplusplus diff --git a/cpu/atmega_common/include/atmega_regs_common.h b/cpu/atmega_common/include/atmega_regs_common.h index bcc142e591..3080dee62f 100644 --- a/cpu/atmega_common/include/atmega_regs_common.h +++ b/cpu/atmega_common/include/atmega_regs_common.h @@ -22,6 +22,7 @@ #define ATMEGA_REGS_COMMON_H #include +#include #ifdef __cplusplus extern "C" { diff --git a/cpu/atmega_common/periph/i2c.c b/cpu/atmega_common/periph/i2c.c index cc78c7cab6..9e8e4b7856 100644 --- a/cpu/atmega_common/periph/i2c.c +++ b/cpu/atmega_common/periph/i2c.c @@ -251,13 +251,13 @@ int i2c_write_regs(i2c_t dev, uint8_t address, uint8_t reg, const void *data, in void i2c_poweron(i2c_t dev) { assert(dev < I2C_NUMOF); - I2C_POWER_REG &= ~(1 << PRTWI); + power_twi_enable(); } void i2c_poweroff(i2c_t dev) { assert(dev < I2C_NUMOF); - I2C_POWER_REG |= (1 << PRTWI); + power_twi_disable(); } static int _start(uint8_t address, uint8_t rw_flag) diff --git a/cpu/atmega_common/periph/spi.c b/cpu/atmega_common/periph/spi.c index 783744bcd5..48824249f6 100644 --- a/cpu/atmega_common/periph/spi.c +++ b/cpu/atmega_common/periph/spi.c @@ -42,7 +42,7 @@ void spi_init(spi_t bus) { assert(bus == 0); /* power off the SPI peripheral */ - MEGA_PRR |= (1 << PRSPI); + power_spi_disable(); /* trigger the pin configuration */ spi_init_pins(bus); } @@ -64,12 +64,11 @@ int spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk) /* lock the bus and power on the SPI peripheral */ mutex_lock(&lock); - MEGA_PRR &= ~(1 << PRSPI); + power_spi_enable(); /* configure as master, with given mode and clock */ SPSR = (clk >> S2X_SHIFT); SPCR = ((1 << SPE) | (1 << MSTR) | mode | (clk & CLK_MASK)); - SPCR |= (1 << SPE); /* clear interrupt flag by reading SPSR and data register by reading SPDR */ (void)SPSR; @@ -82,7 +81,7 @@ void spi_release(spi_t bus) { /* power off and release the bus */ SPCR &= ~(1 << SPE); - MEGA_PRR |= (1 << PRSPI); + power_spi_disable(); mutex_unlock(&lock); }