aboutsummaryrefslogtreecommitdiffstats
path: root/src/wiring/wiring_digital.c
diff options
context:
space:
mode:
authoriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 10:53:07 +0000
committeriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 10:53:07 +0000
commitacf59b1abb346998c492b93fee4a680a32f538d5 (patch)
treec49dd57f489769608095736457a0db9350868a47 /src/wiring/wiring_digital.c
parentaf4c4985cef82b80b936584d686c80d9538082b6 (diff)
downloadlibrambutan-acf59b1abb346998c492b93fee4a680a32f538d5.tar.gz
librambutan-acf59b1abb346998c492b93fee4a680a32f538d5.zip
Added licensing. Moved lots of header files around. Added HardwareSerial reads, writes. Tweaked some of the util and assert functions. Added various useful routines for printing stuff to the serial port. Continued moving out stm32lib. Slightly more consistent naming, this will come in another change.
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@74 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/wiring/wiring_digital.c')
-rw-r--r--src/wiring/wiring_digital.c112
1 files changed, 87 insertions, 25 deletions
diff --git a/src/wiring/wiring_digital.c b/src/wiring/wiring_digital.c
index 1ece41a..456f5da 100644
--- a/src/wiring/wiring_digital.c
+++ b/src/wiring/wiring_digital.c
@@ -1,42 +1,104 @@
-#include "gpio.h"
+/* *****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Created: 12/18/09 02:42:00
+ * Copyright (c) 2009 Perry L. Hung. All rights reserved.
+ *
+ * ****************************************************************************/
+
+/**
+ * @file wiring_digital.c
+ *
+ * @brief
+ */
+
#include "wiring.h"
-#include "util.h"
+#include "io.h"
+#include "gpio.h"
+
+typedef enum AFMode{
+ AF_NONE,
+ AF_PWM,
+ AF_SERIAL,
+ AF_I2C, // unused for now
+ AF_SPI, // unusued for now
+} AFMode;
+
typedef struct PinGPIOMapping {
GPIO_Port *port;
- uint32_t pin;
+ uint32 pin;
} PinGPIOMapping;
+
+/* Reset state is input floating */
static const PinGPIOMapping PIN_TO_GPIO[NR_MAPLE_PINS] = {
- {_GPIOA_BASE, 3}, // D0/PA3
- {_GPIOA_BASE, 2}, // D1/PA2
- {_GPIOA_BASE, 0}, // D2/PA0
- {_GPIOA_BASE, 1}, // D3/PA1
- {_GPIOB_BASE, 5}, // D4/PB5
- {_GPIOB_BASE, 6}, // D5/PB6
- {_GPIOA_BASE, 8}, // D6/PA8
- {_GPIOA_BASE, 9}, // D7/PA9
- {_GPIOA_BASE, 10}, // D8/PA10
- {_GPIOB_BASE, 7}, // D9/PB7
- {_GPIOA_BASE, 4}, // D10/PA4
- {_GPIOA_BASE, 7}, // D11/PA7
- {_GPIOA_BASE, 6}, // D12/PA6
- {_GPIOA_BASE, 5}, // D13/PA5
+ {GPIOA_BASE, 3}, // D0/PA3
+ {GPIOA_BASE, 2}, // D1/PA2
+ {GPIOA_BASE, 0}, // D2/PA0
+ {GPIOA_BASE, 1}, // D3/PA1
+ {GPIOB_BASE, 5}, // D4/PB5
+ {GPIOB_BASE, 6}, // D5/PB6
+ {GPIOA_BASE, 8}, // D6/PA8
+ {GPIOA_BASE, 9}, // D7/PA9
+ {GPIOA_BASE, 10}, // D8/PA10
+ {GPIOB_BASE, 7}, // D9/PB7
+ {GPIOA_BASE, 4}, // D10/PA4
+ {GPIOA_BASE, 7}, // D11/PA7
+ {GPIOA_BASE, 6}, // D12/PA6
+ {GPIOA_BASE, 5}, // D13/PA5
+/* for later */
#if 0
- {_GPIOC_BASE, 0}, // D14/A0/PC0
- {_GPIOC_BASE, 1}, // D15/A1/PC1
- {_GPIOC_BASE, 2}, // D16/A2/PC2
- {_GPIOC_BASE, 3}, // D17/A3/PC3
- {_GPIOC_BASE, 4}, // D18/A4/PC4
- {_GPIOC_BASE, 5}, // D19/A5/PC5
+ {GPIOC_BASE, 0}, // D14/A0/PC0
+ {GPIOC_BASE, 1}, // D15/A1/PC1
+ {GPIOC_BASE, 2}, // D16/A2/PC2
+ {GPIOC_BASE, 3}, // D17/A3/PC3
+ {GPIOC_BASE, 4}, // D18/A4/PC4
+ {GPIOC_BASE, 5}, // D19/A5/PC5
#endif
};
-void pinMode(uint8_t pin, uint8_t mode) {
+void pinMode(uint8_t pin, WiringPinMode mode) {
+ uint8 outputMode;
+
if (pin >= NR_MAPLE_PINS)
return;
- gpio_set_mode(PIN_TO_GPIO[pin].port, PIN_TO_GPIO[pin].pin, mode);
+ switch(mode) {
+ case OUTPUT:
+ outputMode = GPIO_MODE_OUTPUT_PP;
+ break;
+ case INPUT:
+ case INPUT_FLOATING:
+ outputMode = GPIO_MODE_INPUT_FLOATING;
+ break;
+ case INPUT_PULLUP:
+ outputMode = GPIO_MODE_INPUT_PU;
+ break;
+ case INPUT_PULLDOWN:
+ outputMode = GPIO_MODE_INPUT_PD;
+ break;
+ case PWM:
+ outputMode = GPIO_MODE_AF_OUTPUT_PP;
+ break;
+ default:
+ ASSERT(0);
+ return;
+ }
+
+
+ gpio_set_mode(PIN_TO_GPIO[pin].port, PIN_TO_GPIO[pin].pin, outputMode);
}