summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-19 08:34:28 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-09-19 08:34:28 -0400
commit97cda5ea3eb717511dd6feb9ee9cafb45a4f9a7f (patch)
tree9ce26f86be8cde979823ee8671cd27b6f4636c6d
parent9f06b3419173ce1c0f0967676c9eea2915c28418 (diff)
simpler definition of gpio pins
-rw-r--r--bus.c70
-rw-r--r--bus.h17
2 files changed, 43 insertions, 44 deletions
diff --git a/bus.c b/bus.c
index 2bebb57..6b2488b 100644
--- a/bus.c
+++ b/bus.c
@@ -89,7 +89,7 @@ static void pinmux_configurepin(char* pin, int option, int mode)
snprintf(path, sizeof(path), "/sys/kernel/debug/omap_mux/%s", pin);
FILE* node = fopen(path, "w");
if (node != NULL) {
- fprintf(node, "0x%02x\n", (((option << 4) | mode) & 0xff));
+ fprintf(node, "0x%02x\n", (((option << 3) | mode) & 0xff));
fclose(node);
} else {
printf("Failed to configure pin %s (%s)\n", pin, path);
@@ -168,14 +168,14 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs
pinmux_configurepin("gpmc_oen_ren", 0x0, 0x0);
pinmux_configurepin("gpmc_wen", 0x0, 0x0);
- pinmux_configurepin("gpmc_ad7", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad6", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad5", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad4", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad3", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad2", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad1", 0x3, 0x0);
- pinmux_configurepin("gpmc_ad0", 0x3, 0x0);
+ pinmux_configurepin("gpmc_ad7", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad6", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad5", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad4", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad3", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad2", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad1", 0x6, 0x0);
+ pinmux_configurepin("gpmc_ad0", 0x6, 0x0);
pinmux_configurepin("lcd_data0", 0x0, 0x1);
pinmux_configurepin("lcd_data1", 0x0, 0x1);
@@ -211,11 +211,11 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs
* Export a gpio from the kernel to userland
*/
-static int gpio_export(unsigned base, unsigned io)
+static int gpio_export(unsigned gpio_pin)
{
FILE* exportfile = fopen(GPIO_SYSFSPATH"/"GPIO_EXPORTNODE, "w");
if (exportfile != NULL) {
- fprintf(exportfile, "%d\n", base + io);
+ fprintf(exportfile, "%d\n", gpio_pin);
fclose(exportfile);
return 0;
}
@@ -226,11 +226,11 @@ static int gpio_export(unsigned base, unsigned io)
* Un-export a gpio from userland
*/
-static int gpio_unexport(unsigned base, unsigned io)
+static int gpio_unexport(unsigned gpio_pin)
{
FILE* unexportfile = fopen(GPIO_SYSFSPATH"/"GPIO_UNEXPORTNODE, "w");
if (unexportfile != NULL) {
- fprintf(unexportfile, "%d\n", base + io);
+ fprintf(unexportfile, "%d\n", gpio_pin);
fclose(unexportfile);
return 0;
}
@@ -241,10 +241,10 @@ static int gpio_unexport(unsigned base, unsigned io)
* Change a pins direction
*/
-static int gpio_changedirection(unsigned base, unsigned io, bool out)
+static int gpio_changedirection(unsigned gpio_pin, bool out)
{
char path[PATHLEN];
- snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_DIRECTIONNODE, base + io);
+ snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_DIRECTIONNODE, gpio_pin);
FILE* directionfile = fopen(path, "w");
if (directionfile != NULL) {
if (out) {
@@ -259,19 +259,19 @@ static int gpio_changedirection(unsigned base, unsigned io, bool out)
return -1;
}
-static void gpio_getvaluenodepath(unsigned base, unsigned io, char* buffer)
+static void gpio_getvaluenodepath(unsigned gpio_pin, char* buffer)
{
- snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_VALUENODE, base + io);
+ snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_VALUENODE, gpio_pin);
}
/*
* Read a pin's value
*/
-static int gpio_readvalue(unsigned base, unsigned io)
+static int gpio_readvalue(unsigned gpio_pin)
{
char path[PATHLEN];
- gpio_getvaluenodepath(base, io, path);
+ gpio_getvaluenodepath(gpio_pin, path);
FILE* valuefile = fopen(path, "r");
if (valuefile != NULL) {
char value[2]; // value will be a single char and \n
@@ -286,10 +286,10 @@ static int gpio_readvalue(unsigned base, unsigned io)
* Write a pin's value
*/
-static int gpio_writevalue(unsigned base, unsigned io, int value)
+static int gpio_writevalue(unsigned gpio_pin, int value)
{
char path[PATHLEN];
- gpio_getvaluenodepath(base, io, path);
+ gpio_getvaluenodepath(gpio_pin, path);
FILE* valuefile = fopen(path, "w");
if (valuefile != NULL) {
fprintf(valuefile, "%d\n", value);
@@ -299,8 +299,20 @@ static int gpio_writevalue(unsigned base, unsigned io, int value)
return -1;
}
-static unsigned bases[] = { GPIOPIN0BASE, GPIOPIN1BASE, GPIOPIN2BASE, GPIOPIN3BASE, GPIOPIN4BASE, GPIOPIN5BASE };
-static unsigned pins[] = { GPIOPIN0PIN, GPIOPIN1PIN, GPIOPIN2PIN, GPIOPIN3PIN, GPIOPIN4PIN, GPIOPIN5PIN };
+// gpio pins are grouped into 4 bunches of 32 pins
+
+#define GPIO0_X (0 * 32)
+#define GPIO1_X (1 * 32)
+#define GPIO2_X (2 * 32)
+#define GPIO3_X (3 * 32)
+
+static unsigned gpio_pins[] = { GPIO0_X + 22, // i.e., GPIO0_22
+ GPIO0_X + 23,
+ GPIO0_X + 26,
+ GPIO1_X + 15, // i.e., GPIO1_15
+ GPIO1_X + 14,
+ GPIO0_X + 27 };
+
static volatile uint8_t* extbus;
static bool isbb = false;
@@ -322,9 +334,9 @@ void bus_init()
//gpmc_printinfo();
int i;
- for (i = 0; i < SIZEOFARRAY(bases); i++) {
- gpio_export(bases[i], pins[i]);
- gpio_changedirection(bases[i], pins[i], true);
+ for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) {
+ gpio_export(gpio_pins[i]);
+ gpio_changedirection(gpio_pins[i], true);
}
}
}
@@ -332,7 +344,7 @@ void bus_init()
void bus_setpin(int pin, int value)
{
if (isbb) {
- gpio_writevalue(bases[pin], pins[pin], value & 0x1);
+ gpio_writevalue(gpio_pins[pin], value & 0x1);
}
}
@@ -357,8 +369,8 @@ void bus_shutdown()
if (isbb) {
util_unmapmemoryblock((void*) extbus, 0x100);
int i;
- for (i = 0; i < SIZEOFARRAY(bases); i++) {
- gpio_unexport(bases[i], pins[i]);
+ for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) {
+ gpio_unexport(gpio_pins[i]);
}
}
diff --git a/bus.h b/bus.h
index 7031e95..6bb3e83 100644
--- a/bus.h
+++ b/bus.h
@@ -10,6 +10,8 @@
#include <stdint.h>
+
+// these are assigned pins in gpio_pins[] in bus.c
#define out_DATA_LINE 0 /* out data signaled on 0 output of decoder */
#define out_CLOCK_LINE 1 /* out clock signaled on 1 output of decoder */
#define out_STROBE_LINE 2 /* out latch strobe on 2 output of decoder */
@@ -22,21 +24,6 @@
#define Octal_DACportCS_high 0x20
#define TNT_Port 0x40
-
-#define GPIOPIN0BASE 0
-#define GPIOPIN1BASE 0
-#define GPIOPIN2BASE 0
-#define GPIOPIN3BASE 32
-#define GPIOPIN4BASE 32
-#define GPIOPIN5BASE 0
-
-#define GPIOPIN0PIN 22
-#define GPIOPIN1PIN 23
-#define GPIOPIN2PIN 26
-#define GPIOPIN3PIN 15
-#define GPIOPIN4PIN 14
-#define GPIOPIN5PIN 27
-
#define GPMCACCESSTIME 0x07
void bus_init(void); // call this before doing anything