Merge pull request #198 from mazgch/gpio_api

proposed change of gpio_api (new update pull request)
pull/207/head
Bogdan Marinescu 2014-03-10 11:15:59 +00:00
commit 423ddcb86e
52 changed files with 188 additions and 210 deletions

View File

@ -49,12 +49,19 @@ public:
/** Create a DigitalIn connected to the specified pin
*
* @param pin DigitalIn pin to connect to
* @param name (optional) A string to identify the object
*/
DigitalIn(PinName pin) {
gpio_init(&gpio, pin, PIN_INPUT);
gpio_init_in(&gpio, pin);
}
/** Create a DigitalIn connected to the specified pin
*
* @param pin DigitalIn pin to connect to
* @param mode the initial mode of the pin
*/
DigitalIn(PinName pin, PinMode mode) {
gpio_init_in_ex(&gpio, pin, mode);
}
/** Read the input, represented as 0 or 1 (int)
*
* @returns

View File

@ -32,7 +32,18 @@ public:
* @param pin DigitalInOut pin to connect to
*/
DigitalInOut(PinName pin) {
gpio_init(&gpio, pin, PIN_INPUT);
gpio_init_in(&gpio, pin);
}
/** Create a DigitalInOut connected to the specified pin
*
* @param pin DigitalInOut pin to connect to
* @param direction the initial direction of the pin
* @param mode the initial mode of the pin
* @param value the initial value of the pin if is an output
*/
DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) {
gpio_init_inout(&gpio, pin, direction, mode, value);
}
/** Set the output, specified as 0 or 1 (int)

View File

@ -46,7 +46,16 @@ public:
* @param pin DigitalOut pin to connect to
*/
DigitalOut(PinName pin) {
gpio_init(&gpio, pin, PIN_OUTPUT);
gpio_init_out(&gpio, pin);
}
/** Create a DigitalOut connected to the specified pin
*
* @param pin DigitalOut pin to connect to
* @param value the initial pin value
*/
DigitalOut(PinName pin, int value){
gpio_init_out_ex(&gpio, pin, value);
}
/** Set the output, specified as 0 or 1 (int)

View File

@ -21,7 +21,7 @@ namespace mbed {
InterruptIn::InterruptIn(PinName pin) {
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
gpio_init(&gpio, pin, PIN_INPUT);
gpio_init_in(&gpio, pin);
}
InterruptIn::~InterruptIn() {

View File

@ -20,15 +20,15 @@
WEAK void mbed_die(void);
WEAK void mbed_die(void) {
__disable_irq(); // dont allow interrupts to disturb the flash pattern
#if (DEVICE_ERROR_RED == 1)
gpio_t led_red; gpio_init(&led_red, LED_RED, PIN_OUTPUT);
#if (DEVICE_ERROR_RED == 1)
gpio_t led_red; gpio_init_out(&led_red, LED_RED);
#elif (DEVICE_ERROR_PATTERN == 1)
gpio_t led_1; gpio_init(&led_1, LED1, PIN_OUTPUT);
gpio_t led_2; gpio_init(&led_2, LED2, PIN_OUTPUT);
gpio_t led_3; gpio_init(&led_3, LED3, PIN_OUTPUT);
gpio_t led_4; gpio_init(&led_4, LED4, PIN_OUTPUT);
gpio_t led_1; gpio_init_out(&led_1, LED1);
gpio_t led_2; gpio_init_out(&led_2, LED2);
gpio_t led_3; gpio_init_out(&led_3, LED3);
gpio_t led_4; gpio_init_out(&led_4, LED4);
#endif
while (1) {

View File

@ -0,0 +1,56 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gpio_api.h"
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
{
gpio_init(gpio, pin);
gpio_mode(gpio, mode);
gpio_dir(gpio, PIN_INPUT);
}
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
{
gpio_init(gpio, pin);
gpio_write(gpio, value);
gpio_dir(gpio, PIN_OUTPUT);
gpio_mode(gpio, mode);
}
void gpio_init_in(gpio_t* gpio, PinName pin) {
gpio_init_in_ex(gpio, pin, PullDefault);
}
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) {
_gpio_init_in(gpio, pin, mode);
}
void gpio_init_out(gpio_t* gpio, PinName pin) {
gpio_init_out_ex(gpio, pin, 0);
}
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
_gpio_init_out(gpio, pin, PullNone, value);
}
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
if (direction == PIN_INPUT) {
_gpio_init_in(gpio, pin, mode);
gpio_write(gpio, value); // we prepare the value in case it is switched later
} else {
_gpio_init_out(gpio, pin, mode, value);
}
}

View File

@ -29,7 +29,7 @@ extern "C" {
uint32_t gpio_set(PinName pin);
/* GPIO object */
void gpio_init (gpio_t *obj, PinName pin, PinDirection direction);
void gpio_init(gpio_t *obj, PinName pin);
void gpio_mode (gpio_t *obj, PinMode mode);
void gpio_dir (gpio_t *obj, PinDirection direction);
@ -37,6 +37,13 @@ void gpio_dir (gpio_t *obj, PinDirection direction);
void gpio_write(gpio_t *obj, int value);
int gpio_read (gpio_t *obj);
// the following set of functions are generic and are implemented in the common gpio.c file
void gpio_init_in(gpio_t* gpio, PinName pin);
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode);
void gpio_init_out(gpio_t* gpio, PinName pin);
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value);
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value);
#ifdef __cplusplus
}
#endif

View File

@ -240,6 +240,7 @@ typedef enum {
PullNone = 0,
PullDown = 2,
PullUp = 3,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus

View File

@ -21,7 +21,7 @@ uint32_t gpio_set(PinName pin) {
return 1 << ((pin & 0x7F) >> 2);
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC)
return;
@ -35,16 +35,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &reg->PCOR;
obj->reg_in = &reg->PDIR;
obj->reg_dir = &reg->PDDR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT:
pin_mode(pin, PullNone);
break;
case PIN_INPUT :
pin_mode(pin, PullUp);
break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -126,6 +126,7 @@ typedef enum {
typedef enum {
PullNone = 0,
PullUp = 2,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus

View File

@ -17,6 +17,7 @@
#include "cmsis.h"
#include "gpio_irq_api.h"
#include "gpio_api.h"
#include "error.h"
#define CHANNEL_NUM 64 // 31 pins on 2 ports
@ -176,9 +177,8 @@ void gpio_irq_disable(gpio_irq_t *obj) {
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
extern void gpio_init(gpio_t *obj, PinName pin, PinDirection direction);
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init(&gpio, PTB5, PIN_INPUT);
gpio_init_in(&gpio, PTA4);
}

View File

@ -244,6 +244,7 @@ typedef enum {
typedef enum {
PullNone = 0,
PullUp = 2,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus

View File

@ -17,6 +17,7 @@
#include "cmsis.h"
#include "gpio_irq_api.h"
#include "gpio_api.h"
#include "error.h"
#define CHANNEL_NUM 64
@ -166,9 +167,8 @@ void gpio_irq_disable(gpio_irq_t *obj) {
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
extern void gpio_init(gpio_t *obj, PinName pin, PinDirection direction);
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init(&gpio, PTA4, PIN_INPUT);
gpio_init_in(&gpio, PTA4);
}

View File

@ -247,7 +247,8 @@ typedef enum {
typedef enum {
PullNone = 0,
PullDown = 2,
PullUp = 3
PullUp = 3,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus

View File

@ -17,6 +17,7 @@
#include "cmsis.h"
#include "gpio_irq_api.h"
#include "gpio_api.h"
#include "error.h"
#define CHANNEL_NUM 96
@ -186,9 +187,8 @@ void gpio_irq_disable(gpio_irq_t *obj) {
// Change the NMI pin to an input. This allows NMI pin to
// be used as a low power mode wakeup. The application will
// need to change the pin back to NMI_b or wakeup only occurs once!
extern void gpio_init(gpio_t *obj, PinName pin, PinDirection direction);
void NMI_Handler(void)
{
gpio_t gpio;
gpio_init(&gpio, PTA4, PIN_INPUT);
gpio_init_in(&gpio, PTA4);
}

View File

@ -21,7 +21,7 @@ uint32_t gpio_set(PinName pin) {
return 1 << ((pin & 0x7F) >> 2);
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == (PinName)NC) return;
obj->pin = pin;
@ -34,12 +34,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &reg->PCOR;
obj->reg_in = &reg->PDIR;
obj->reg_dir = &reg->PDDR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullUp); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -142,7 +142,8 @@ typedef enum {
typedef enum {
PullNone = 0,
PullDown = 1,
PullUp = 3
PullUp = 3,
PullDefault = PullUp
} PinMode;
#ifdef __cplusplus

View File

@ -16,7 +16,7 @@
#include "gpio_api.h"
#include "pinmap.h"
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -26,12 +26,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &NRF_GPIO->OUTCLR;
obj->reg_in = &NRF_GPIO->IN;
obj->reg_dir = &NRF_GPIO->DIR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullUp); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -155,7 +155,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -178,7 +178,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -150,7 +150,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -27,7 +27,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -39,12 +39,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &LPC_GPIO->CLR[port];
obj->reg_in = &LPC_GPIO->PIN[port];
obj->reg_dir = &LPC_GPIO->DIR[port];
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -208,7 +208,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -223,7 +223,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -34,7 +34,7 @@ uint32_t gpio_set(PinName pin) {
return ((pin & 0x0F00) >> 8);
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -43,13 +43,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)];
obj->reg_dir = &port_reg->DIR;
obj->reg_write = &port_reg->DATA;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -140,7 +140,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -27,7 +27,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -39,12 +39,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &LPC_GPIO->CLR[port];
obj->reg_in = &LPC_GPIO->PIN[port];
obj->reg_dir = &LPC_GPIO->DIR[port];
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -81,7 +81,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#define STDIO_UART_TX USBTX

View File

@ -33,7 +33,7 @@ uint32_t gpio_set(PinName pin) {
return (1UL << ((int)pin & 0x1f));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -45,12 +45,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &LPC_GPIO_PORT->CLR[port];
obj->reg_in = &LPC_GPIO_PORT->PIN[port];
obj->reg_dir = &LPC_GPIO_PORT->DIR[port];
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -112,7 +112,8 @@ typedef enum {
PullUp = 0,
PullDown = 3,
PullNone = 2,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
// version of PINCON_TypeDef using register arrays

View File

@ -8,29 +8,19 @@ void mbed_sdk_init()
gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet;
gpio_t gpsEn, gpsRst, led, modemRts;
gpio_init(&modemEn, MDMEN, PIN_OUTPUT);
gpio_init(&modemRst, MDMRST, PIN_OUTPUT);
gpio_init(&modemPwrOn, MDMPWRON, PIN_OUTPUT);
gpio_init(&modemLvlOe, MDMLVLOE, PIN_OUTPUT);
gpio_init(&modemILvlOe, MDMILVLOE, PIN_OUTPUT);
gpio_init(&modemUsbDet, MDMUSBDET, PIN_OUTPUT);
gpio_init(&gpsEn, GPSEN, PIN_OUTPUT);
gpio_init(&gpsRst, GPSRST, PIN_OUTPUT);
gpio_init(&led, LED, PIN_OUTPUT);
gpio_init(&modemRts, MDMRTS, PIN_OUTPUT);
gpio_write(&led, 0); // LED1: 0=off
gpio_write(&modemRts, 0); // RTS: 0=ready to send
// we start with the gps disabled
gpio_write(&gpsEn, 0); // LDOEN: 1=on,0=off
gpio_write(&gpsRst, 0); // RESET: 0=reset,1=operating
// we start with the modem disabled
gpio_write(&modemLvlOe, 1); // LVLEN: 1=disabled (uart/gpio)
gpio_write(&modemILvlOe, 0); // ILVLEN: 0=disabled (i2c)
gpio_write(&modemUsbDet, 0); // USBDET: 0=disabled
gpio_write(&modemPwrOn, 1); // PWRON: 1=idle, 0=action
gpio_write(&modemEn, 0); // LDOEN: 1=on, 0=off
gpio_write(&modemRst, 0); // RESET: 0=reset, 1=operating
// start with modem disabled
gpio_init_out_ex(&modemEn, MDMEN, PullNone, 0);
gpio_init_out_ex(&modemRst, MDMRST, PullNone, 1);
gpio_init_out_ex(&modemPwrOn, MDMPWRON, PullNone, 1);
gpio_init_out_ex(&modemLvlOe, MDMLVLOE, PullNone, 1);
gpio_init_out_ex(&modemILvlOe, MDMILVLOE, PullNone, 0);
gpio_init_out_ex(&modemUsbDet, MDMUSBDET, PullNone, 0);
gpio_init_out_ex(&modemRts, MDMRTS, PullNone, 0);
// start with gps disabled
gpio_init_out_ex(&gpsEn, GPSEN, PullNone, 0);
gpio_init_out_ex(&gpsRst, GPSRST, PullNone, 1);
// led should be off
gpio_init_out_ex(&led, LED, PullNone, 0);
wait_ms(50); // when USB cable is inserted the interface chip issues
// multiple resets to the target CPU We wait here for a short period to

View File

@ -21,7 +21,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -32,12 +32,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &port_reg->FIOCLR;
obj->reg_in = &port_reg->FIOPIN;
obj->reg_dir = &port_reg->FIODIR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -76,7 +76,7 @@ serial_t stdio_uart;
struct serial_global_data_s {
uint32_t serial_irq_id;
gpio_t sw_rts, sw_cts;
uint8_t count, rx_irq_set_flow, rx_irq_set_api;
uint8_t rx_irq_set_flow, rx_irq_set_api;
};
static struct serial_global_data_s uart_data[UART_NUM];
@ -357,7 +357,6 @@ int serial_getc(serial_t *obj) {
void serial_putc(serial_t *obj, int c) {
while (!serial_writable(obj));
obj->uart->THR = c;
uart_data[obj->index].count++;
}
int serial_readable(serial_t *obj) {
@ -365,16 +364,10 @@ int serial_readable(serial_t *obj) {
}
int serial_writable(serial_t *obj) {
int isWritable = 1;
if (NC != uart_data[obj->index].sw_cts.pin)
isWritable = (gpio_read(&uart_data[obj->index].sw_cts) == 0) && (obj->uart->LSR & 0x40);
else {
if (obj->uart->LSR & 0x20)
uart_data[obj->index].count = 0;
else if (uart_data[obj->index].count >= 16)
isWritable = 0;
}
return isWritable;
return (gpio_read(&uart_data[obj->index].sw_cts) == 0) && (obj->uart->LSR & 0x40); //If flow control: writable if CTS low + UART done
else
return obj->uart->LSR & 0x20; //No flow control: writable if space in holding register
}
void serial_clear(serial_t *obj) {
@ -419,7 +412,7 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
pinmap_pinout(txflow, PinMap_UART_CTS);
} else {
// Can't enable in hardware, use software emulation
gpio_init(&uart_data[index].sw_cts, txflow, PIN_INPUT);
gpio_init_in(&uart_data[index].sw_cts, txflow);
}
}
if (((FlowControlRTS == type) || (FlowControlRTSCTS == type)) && (NC != rxflow)) {
@ -434,8 +427,7 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi
uart1->MCR |= UART_MCR_RTSEN_MASK;
pinmap_pinout(rxflow, PinMap_UART_RTS);
} else { // can't enable in hardware, use software emulation
gpio_init(&uart_data[index].sw_rts, rxflow, PIN_OUTPUT);
gpio_write(&uart_data[index].sw_rts, 0);
gpio_init_out_ex(&uart_data[index].sw_rts, rxflow, 0);
// Enable RX interrupt
serial_flow_irq_set(obj, 1);
}

View File

@ -84,7 +84,8 @@ typedef enum {
PullUp = 0,
PullDown = 3,
PullNone = 2,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
// version of PINCON_TypeDef using register arrays

View File

@ -24,7 +24,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
obj->pin = pin;
@ -36,12 +36,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &port_reg->FIOCLR;
obj->reg_in = &port_reg->FIOPIN;
obj->reg_dir = &port_reg->FIODIR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -91,7 +91,8 @@ typedef enum {
PullUp = 2,
PullDown = 1,
PullNone = 0,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;

View File

@ -21,7 +21,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
obj->pin = pin;
@ -33,12 +33,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &port_reg->CLR;
obj->reg_in = &port_reg->PIN;
obj->reg_dir = &port_reg->DIR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -556,7 +556,8 @@ typedef enum {
PullDown = 3,
PullNone = 2,
Repeater = 1,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -28,7 +28,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
obj->pin = pin;
@ -41,12 +41,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &port_reg->CLR[port];
obj->reg_in = &port_reg->PIN[port];
obj->reg_dir = &port_reg->DIR[port];
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -62,7 +62,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#define STDIO_UART_TX USBTX

View File

@ -88,7 +88,8 @@ typedef enum {
PullDown = 1,
PullNone = 0,
Repeater = 3,
OpenDrain = 4
OpenDrain = 4,
PullDefault = PullDown
} PinMode;
#define STDIO_UART_TX USBTX

View File

@ -39,7 +39,7 @@ uint32_t gpio_set(PinName pin) {
return (1 << ((int)pin & 0x1F));
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -49,12 +49,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_clr = &LPC_GPIO_PORT->CLR0;
obj->reg_in = &LPC_GPIO_PORT->PIN0;
obj->reg_dir = &LPC_GPIO_PORT->DIR0;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -166,7 +166,8 @@ typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3
OpenDrain = 3,
PullDefault = PullNone
} PinMode;
#ifdef __cplusplus

View File

@ -41,7 +41,7 @@ uint32_t gpio_set(PinName pin) {
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
uint32_t port_index = STM_PORT(pin);
@ -56,14 +56,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRR;
obj->reg_clr = &gpio->BRR;
// Configure GPIO
if (direction == PIN_OUTPUT) {
pin_function(pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
}
else { // PIN_INPUT
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -156,7 +156,8 @@ typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3
OpenDrain = 3,
PullDefault = PullNone
} PinMode;
#ifdef __cplusplus

View File

@ -41,7 +41,7 @@ uint32_t gpio_set(PinName pin) {
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
uint32_t port_index = STM_PORT(pin);
@ -56,14 +56,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRR;
obj->reg_clr = &gpio->BRR;
// Configure GPIO
if (direction == PIN_OUTPUT) {
pin_function(pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
}
else { // PIN_INPUT
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -168,7 +168,8 @@ typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3
OpenDrain = 3,
PullDefault = PullNone
} PinMode;
#ifdef __cplusplus

View File

@ -42,7 +42,7 @@ uint32_t gpio_set(PinName pin) {
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
uint32_t port_index = STM_PORT(pin);
@ -57,14 +57,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRRL;
obj->reg_clr = &gpio->BSRRH;
// Configure GPIO
if (direction == PIN_OUTPUT) {
pin_function(pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
}
else { // PIN_INPUT
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -161,7 +161,8 @@ typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3
OpenDrain = 3,
PullDefault = PullNone
} PinMode;
#ifdef __cplusplus

View File

@ -41,7 +41,7 @@ uint32_t gpio_set(PinName pin) {
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if (pin == NC) return;
uint32_t port_index = STM_PORT(pin);
@ -56,14 +56,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRRL;
obj->reg_clr = &gpio->BSRRH;
// Configure GPIO
if (direction == PIN_OUTPUT) {
pin_function(pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
}
else { // PIN_INPUT
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {

View File

@ -51,7 +51,8 @@ typedef enum {
PullNone = 0,
PullUp = 1,
PullDown = 2,
OpenDrain = 3
OpenDrain = 3,
PullDefault = PullDown
} PinMode;
#ifdef __cplusplus

View File

@ -26,7 +26,7 @@ uint32_t gpio_set(PinName pin) {
return 1 << ((uint32_t) pin & 0xF);
}
void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
void gpio_init(gpio_t *obj, PinName pin) {
if(pin == NC) return;
obj->pin = pin;
@ -39,14 +39,6 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
obj->reg_set = &port_reg->BSRRL;
obj->reg_clr = &port_reg->BSRRH;
obj->reg_in = &port_reg->IDR;
gpio_dir(obj, direction);
switch (direction) {
case PIN_OUTPUT: pin_mode(pin, PullNone); break;
case PIN_INPUT : pin_mode(pin, PullDown); break;
}
}
void gpio_mode(gpio_t *obj, PinMode mode) {