Change enumeration

This commit is contained in:
Michael Hayes
2011-09-06 03:21:05 +00:00
parent eb86788414
commit 7f321e75a9
2 changed files with 21 additions and 21 deletions
+18 -14
View File
@@ -7,6 +7,10 @@
#include "pio-simple.h"
#define PIO_BITMASK(PIO) (BIT((PIO) & 7)
#define PIO_PORT(PIO) ((PIO) >> 3)
/** Configure pio
@param pio */
@@ -14,9 +18,9 @@ bool pio_config_set (pio_t pio, pio_config_t config)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
switch (config)
@@ -115,9 +119,9 @@ void pio_output_high (pio_t pio)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
PORTB |= bitmask;
@@ -143,9 +147,9 @@ void pio_output_low (pio_t pio)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
PORTB &= ~bitmask;
@@ -171,9 +175,9 @@ void pio_output_toggle (pio_t pio)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
PORTB ^= bitmask;
@@ -200,9 +204,9 @@ bool pio_input_get (pio_t pio)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
return (PINB & bitmask) != 0;
@@ -240,9 +244,9 @@ pio_config_t pio_config_get (pio_t pio)
bool port;
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
ddr = (DDRB & bitmask) != 0;
@@ -285,9 +289,9 @@ bool pio_output_get (pio_t pio)
{
uint8_t bitmask;
bitmask = BIT (pio.bit);
bitmask = PIO_BITMASK (pio);
switch (pio.port)
switch (PIO_PORT (pio))
{
case PORT_B:
return (PORTB & bitmask) != 0;
+3 -7
View File
@@ -14,13 +14,9 @@ typedef enum pio_port_enum
PORT_A, PORT_B, PORT_C, PORT_D, PORT_E
} pio_port_t;
typedef uint8_t pio_bit_t;
typedef struct pio_struct
{
pio_port_t port;
pio_bit_t bit;
} pio_t;
typedef uint8_t pio_t;
typedef enum pio_config_enum
{
@@ -29,7 +25,7 @@ typedef enum pio_config_enum
/* Define a PIO as a structure in terms of a port and a bit. */
#define PIO_DEFINE(PORT, PORTBIT) (pio_t){PORT, PORTBIT}
#define PIO_DEFINE(PORT, PORTBIT) ((PORT) * 8 + (PORTBIT))
/** Configure pio.