]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/gpio.c
Rename pin.. to gpio..
[z180-stamp.git] / avr / gpio.c
similarity index 88%
rename from avr/pin.c
rename to avr/gpio.c
index 6e88aa576c561f280aecc82a57be5f44070e4502..3c47247ef64baf90ff66b18e198713cec3c97cf6 100644 (file)
--- a/avr/pin.c
@@ -2,7 +2,7 @@
 #include <util/atomic.h>
 #include <limits.h>
 #include "debug.h"
-#include "pin.h"
+#include "gpio.h"
 
 
 /*
@@ -32,7 +32,7 @@ pre   Timer0          Timer1          Timer2
 5      1024    x4      1024    x4      128     x2
 6                                      256     x2
 7                                      1024    x4
---------------------------------------------------                                     
+--------------------------------------------------
 
 */
 
@@ -42,10 +42,10 @@ pre Timer0          Timer1          Timer2
 #define PWMNEG         0b11
 
 
-const FLASH uint8_t prescale_factors_01[] = 
+const FLASH uint8_t prescale_factors_01[] =
        { 8, 8, 4, 4, 0 };
 
-const FLASH uint8_t prescale_factors_2[] = 
+const FLASH uint8_t prescale_factors_2[] =
        { 8, 4, 2, 2, 2, 4, 0 };
 
 typedef volatile struct {
@@ -69,7 +69,7 @@ struct pindef_s {
 };
 
 
-const FLASH struct pindef_s pinlist[PIN_MAX] = {
+const FLASH struct pindef_s pinlist[GPIO_MAX] = {
        { (port_t *) &PING, _BV(5), TIMER0 | CHANB },
        { (port_t *) &PING, _BV(4), NO_TIMER },
        { (port_t *) &PINB, _BV(4), TIMER2 | CHANA },
@@ -82,11 +82,11 @@ const FLASH struct pindef_s pinlist[PIN_MAX] = {
        { (port_t *) &PING, _BV(0), NO_TIMER },
        { (port_t *) &PINE, _BV(7), NO_TIMER },
 };
-       
-void pin_timer_off(uint8_t timertype)
+
+void gpio_timer_off(uint8_t timertype)
 {
        uint8_t chan_mask;
-       
+
        if (timertype & CHANA)
                chan_mask = 0xc0;
        else
@@ -117,7 +117,7 @@ void pin_timer_off(uint8_t timertype)
        }
 }
 
-int pin_config(int pin, pinmode_t mode)
+int gpio_config(int pin, gpiomode_t mode)
 {
        if ((unsigned) pin >= ARRAY_SIZE(pinlist)) {
                /* Invalid pin number */
@@ -126,24 +126,24 @@ int pin_config(int pin, pinmode_t mode)
 
                port_t *p = pinlist[pin].adr;
                uint8_t bit = pinlist[pin].mask;
-       
+
                switch (mode) {
                case INPUT:
-                       pin_timer_off(pinlist[pin].timer);
+                       gpio_timer_off(pinlist[pin].timer);
                        ATOMIC_BLOCK(ATOMIC_FORCEON) {
                                p->ddr &= ~bit;
                                p->pout &= ~bit;
                        }
                        break;
                case INPUT_PULLUP:
-                       pin_timer_off(pinlist[pin].timer);
+                       gpio_timer_off(pinlist[pin].timer);
                        ATOMIC_BLOCK(ATOMIC_FORCEON) {
                                p->ddr &= ~bit;
                                p->pout |= bit;
                        }
                        break;
                case OUTPUT:
-                       pin_timer_off(pinlist[pin].timer);
+                       gpio_timer_off(pinlist[pin].timer);
                case OUTPUT_TIMER:
                        ATOMIC_BLOCK(ATOMIC_FORCEON) {
                                p->ddr |= bit;
@@ -157,11 +157,11 @@ int pin_config(int pin, pinmode_t mode)
        return 0;
 }
 
-void pin_write(int pin, uint8_t val)
+void gpio_write(int pin, uint8_t val)
 {
        port_t *p = pinlist[pin].adr;
        uint8_t bit = pinlist[pin].mask;
-       
+
        ATOMIC_BLOCK(ATOMIC_FORCEON) {
                if (val)
                        p->pout |= bit;
@@ -170,20 +170,20 @@ void pin_write(int pin, uint8_t val)
        }
 }
 
-int pin_read(int pin)
+int gpio_read(int pin)
 {
        port_t *p = pinlist[pin].adr;
        uint8_t bit = pinlist[pin].mask;
-       
+
        return (p->pin & bit) != 0;
 }
 
-pinmode_t pin_config_get(int pin) 
+gpiomode_t gpio_config_get(int pin)
 {
        uint8_t timertype = pinlist[pin].timer;
 
        if (timertype & TIMER) {
-       
+
                uint8_t chan_mask;
                if (timertype & CHANA)
                        chan_mask = 0xc0;
@@ -205,26 +205,26 @@ pinmode_t pin_config_get(int pin)
                        break;
                }
        }
-       
+
        port_t *p = pinlist[pin].adr;
        uint8_t bit = pinlist[pin].mask;
 
        if (p->ddr & bit)
                return OUTPUT;
-       
+
        if (p->pout & bit)
                return INPUT_PULLUP;
-               
+
        return INPUT;
 }
-       
+
 /*
  * return -1: pin has no timer output
  *        0: pin is not configured for timer output
  *      > 0: divider
  */
-long pin_clockdiv_get(int pin)
+
+long gpio_clockdiv_get(int pin)
 {
        long divider;
        uint8_t prescale;
@@ -234,9 +234,9 @@ long pin_clockdiv_get(int pin)
        if ((timertype & TIMER) == 0)
                return -1;
 
-       if (pin_config_get(pin) != OUTPUT_TIMER)
+       if (gpio_config_get(pin) != OUTPUT_TIMER)
                return 0;
-       
+
        switch (timertype & TIMER) {
        case TIMER0:
                prescale = TCCR0B;
@@ -257,19 +257,19 @@ long pin_clockdiv_get(int pin)
        prescale = (prescale & 0x07) - 1;
        divider += 1;
 
-       pstab = (timertype & TIMER) == TIMER2 ? 
+       pstab = (timertype & TIMER) == TIMER2 ?
                        prescale_factors_2 : prescale_factors_01;
-                       
+
        while (prescale--)
                divider *= pstab[prescale];
-                       
+
        if ((timertype & (CHANA|T_16BIT)) == CHANA)
                divider *= 2;
-               
+
        return divider;
 }
 
-int pin_clockdiv_set(int pin, unsigned long divider)
+int gpio_clockdiv_set(int pin, unsigned long divider)
 {
        unsigned long ltop;
        uint16_t top;
@@ -282,18 +282,18 @@ int pin_clockdiv_set(int pin, unsigned long divider)
 
        if (divider < 2)
                return -1;
-               
+
        ltop = divider;
        if ((timertype & (CHANA|T_16BIT)) == CHANA)
                ltop /= 2;
-               
+
        if (ltop > 1024 * ((timertype & T_16BIT) ? (1L<<16) : (1L<<8)))
                return -1;
 
        prescale = 1;
-       pstab = (timertype & TIMER) == TIMER2 ? 
+       pstab = (timertype & TIMER) == TIMER2 ?
                        prescale_factors_2 : prescale_factors_01;
-                       
+
 //     debug("** clockdiv_set: pin: %d, ltop: %lu, prescale: %d\n",
 //             pin, ltop, prescale);
 
@@ -365,8 +365,7 @@ int pin_clockdiv_set(int pin, unsigned long divider)
 
        PING |= _BV(0);         /* Debug */
 
-       pin_config(pin, OUTPUT_TIMER);
+       gpio_config(pin, OUTPUT_TIMER);
 
        return 0;
 }
-