You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/04/08 20:14:10 UTC
[5/7] incubator-mynewt-core git commit: Changing return type to "int"
for hal_gpio_toggle Changing return type to "int" for hal_gpio_toggle &
removing trailing spaces
Changing return type to "int" for hal_gpio_toggle
Changing return type to "int" for hal_gpio_toggle & removing trailing
spaces
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/274da326
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/274da326
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/274da326
Branch: refs/heads/develop
Commit: 274da3263a0fbd8457b8ecae96cc75b5e56d77ca
Parents: 73b2b80
Author: Vipul Rahane <vi...@runtime.io>
Authored: Thu Apr 7 16:30:48 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Thu Apr 7 16:30:48 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_gpio.h | 74 +++++-----
hw/mcu/native/src/hal_gpio.c | 8 +-
hw/mcu/nordic/nrf51xxx/src/hal_gpio.c | 212 +++++++++++++--------------
hw/mcu/nordic/nrf52xxx/src/hal_gpio.c | 212 +++++++++++++--------------
hw/mcu/stm/stm32f4xx/src/hal_gpio.c | 228 ++++++++++++++---------------
5 files changed, 369 insertions(+), 365 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/274da326/hw/hal/include/hal/hal_gpio.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_gpio.h b/hw/hal/include/hal/hal_gpio.h
index b7eb1fa..cc8a3fe 100644
--- a/hw/hal/include/hal/hal_gpio.h
+++ b/hw/hal/include/hal/hal_gpio.h
@@ -44,7 +44,7 @@ enum gpio_pull
typedef enum gpio_pull gpio_pull_t;
/*
- * IRQ trigger type.
+ * IRQ trigger type.
*/
enum gpio_irq_trigger
{
@@ -61,78 +61,80 @@ typedef enum gpio_irq_trigger gpio_irq_trig_t;
typedef void (*gpio_irq_handler_t)(void *arg);
/**
- * gpio init in
- *
- * Initializes the specified pin as an input
- *
+ * gpio init in
+ *
+ * Initializes the specified pin as an input
+ *
* @param pin Pin number to set as input
* @param pull pull type
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int hal_gpio_init_in(int pin, gpio_pull_t pull);
/**
- * gpio init out
- *
- * Initialize the specified pin as an output, setting the pin to the specified
- * value.
- *
+ * gpio init out
+ *
+ * Initialize the specified pin as an output, setting the pin to the specified
+ * value.
+ *
* @param pin Pin number to set as output
* @param val Value to set pin
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int hal_gpio_init_out(int pin, int val);
/**
- * gpio set
- *
- * Sets specified pin to 1 (high)
- *
- * @param pin
+ * gpio set
+ *
+ * Sets specified pin to 1 (high)
+ *
+ * @param pin
*/
void hal_gpio_set(int pin);
/**
* gpio clear
- *
- * Sets specified pin to 0 (low).
- *
- * @param pin
+ *
+ * Sets specified pin to 0 (low).
+ *
+ * @param pin
*/
void hal_gpio_clear(int pin);
/**
- * gpio write
- *
+ * gpio write
+ *
* Write a value (either high or low) to the specified pin.
- *
+ *
* @param pin Pin to set
* @param val Value to set pin (0:low 1:high)
*/
void hal_gpio_write(int pin, int val);
/**
- * gpio read
- *
- * Reads the specified pin.
- *
- *
+ * gpio read
+ *
+ * Reads the specified pin.
+ *
+ *
* @param pin Pin number to read
- *
+ *
* @return int 0: low, 1: high
*/
int hal_gpio_read(int pin);
/**
- * gpio toggle
- *
+ * gpio toggle
+ *
* Toggles the specified pin
- *
+ *
* @param pin Pin number to toggle
+ *
+ * @return current gpio state int 0: low, 1: high
*/
-void hal_gpio_toggle(int pin);
+int hal_gpio_toggle(int pin);
int hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
gpio_irq_trig_t trig, gpio_pull_t pull);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/274da326/hw/mcu/native/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/native/src/hal_gpio.c b/hw/mcu/native/src/hal_gpio.c
index 677b738..2da4e34 100644
--- a/hw/mcu/native/src/hal_gpio.c
+++ b/hw/mcu/native/src/hal_gpio.c
@@ -81,7 +81,7 @@ void hal_gpio_write(int pin, int val)
return;
}
hal_gpio[pin].val = (val != 0);
- printf("hal_gpio set pin %2d to %1d\r", pin, hal_gpio[pin].val);
+ printf("hal_gpio set pin %2d to %1d\r", pin, hal_gpio[pin].val);
fflush(stdout);
}
@@ -94,8 +94,10 @@ hal_gpio_read(int pin)
return hal_gpio[pin].val;
}
-void
+int
hal_gpio_toggle(int pin)
{
- hal_gpio_write(pin, hal_gpio_read(pin) != 1);
+ int pin_state = (hal_gpio_read(pin) != 1);
+ hal_gpio_write(pin, pin_state);
+ return pin_state;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/274da326/hw/mcu/nordic/nrf51xxx/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_gpio.c b/hw/mcu/nordic/nrf51xxx/src/hal_gpio.c
index 05fe6fc..6aac418 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_gpio.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_gpio.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -26,28 +26,28 @@
/* XXX: Notes
* 1) Right now, we are not disabling the NVIC interrupt source; we only
* disable the external interrupt from occurring. Dont think either way
- * to do it is an issue... when we release we may want to disable the NVIC
- *
+ * to do it is an issue... when we release we may want to disable the NVIC
+ *
* 2) investigate how thread safe these routines are. HAL_GPIO_Init, for
* example. Looks like if it gets interrupted while doing config an error
- * may occur. Read/modify write could cause screw-ups.
- *
- * 3) Currently, this code does not change the interrupt priority of the
- * external interrupt vectors in the NVIC. The application developer must
- * decide on the priority level for each external interrupt and program that
- * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
- *
- * 4) The code probably does not handle "re-purposing" gpio very well.
- * "Re-purposing" means changing a gpio from input to output, or calling
- * gpio_init_in and expecting previously enabled interrupts to be stopped.
- *
- * 5) Possbily add access to HAL_GPIO_DeInit.
+ * may occur. Read/modify write could cause screw-ups.
+ *
+ * 3) Currently, this code does not change the interrupt priority of the
+ * external interrupt vectors in the NVIC. The application developer must
+ * decide on the priority level for each external interrupt and program that
+ * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
+ *
+ * 4) The code probably does not handle "re-purposing" gpio very well.
+ * "Re-purposing" means changing a gpio from input to output, or calling
+ * gpio_init_in and expecting previously enabled interrupts to be stopped.
+ *
+ * 5) Possbily add access to HAL_GPIO_DeInit.
*/
-/*
+/*
* GPIO pin mapping
- *
- */
+ *
+ */
#define GPIO_INDEX(pin) (pin)
#define GPIO_MASK(pin) (1 << GPIO_INDEX(pin))
@@ -76,11 +76,11 @@ struct ext_irqs ext_irq_counts;
#if 0
/**
- * ext irq handler
- *
- * Handles the gpio interrupt attached to a gpio pin.
- *
- * @param index
+ * ext irq handler
+ *
+ * Handles the gpio interrupt attached to a gpio pin.
+ *
+ * @param index
*/
static void
ext_irq_handler(int index)
@@ -128,9 +128,9 @@ ext_irq3(void)
/**
* ext irq4
- *
+ *
* External interrupt handler for external interrupt 4.
- *
+ *
*/
static void
ext_irq4(void)
@@ -140,10 +140,10 @@ ext_irq4(void)
}
/**
- * ext irq9_5
- *
- * External interrupt handler for irqs 9 through 5.
- *
+ * ext irq9_5
+ *
+ * External interrupt handler for irqs 9 through 5.
+ *
*/
static void
ext_irq9_5(void)
@@ -157,10 +157,10 @@ ext_irq9_5(void)
}
/**
- * ext irq15_10
- *
- * External interrupt handler for irqs 15 through 10.
- *
+ * ext irq15_10
+ *
+ * External interrupt handler for irqs 15 through 10.
+ *
*/
static void
ext_irq15_10(void)
@@ -174,13 +174,13 @@ ext_irq15_10(void)
}
/**
- * hal gpio clk enable
- *
- * Enable the port peripheral clock
- *
- * @param port_idx
+ * hal gpio clk enable
+ *
+ * Enable the port peripheral clock
+ *
+ * @param port_idx
*/
-static void
+static void
hal_gpio_clk_enable(uint32_t port_idx)
{
switch (port_idx) {
@@ -236,14 +236,14 @@ hal_gpio_clk_enable(uint32_t port_idx)
}
/**
- * hal gpio pin to irq
- *
- * Converts the logical pin number to the IRQ number associated with the
- * external interrupt for that particular GPIO.
- *
- * @param pin
- *
- * @return IRQn_Type
+ * hal gpio pin to irq
+ *
+ * Converts the logical pin number to the IRQ number associated with the
+ * external interrupt for that particular GPIO.
+ *
+ * @param pin
+ *
+ * @return IRQn_Type
*/
static IRQn_Type
hal_gpio_pin_to_irq(int pin)
@@ -306,14 +306,14 @@ hal_gpio_set_nvic(IRQn_Type irqn)
}
/**
- * gpio init in
- *
- * Initializes the specified pin as an input
- *
+ * gpio init in
+ *
+ * Initializes the specified pin as an input
+ *
* @param pin Pin number to set as input
* @param pull pull type
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int
hal_gpio_init_in(int pin, gpio_pull_t pull)
@@ -340,15 +340,15 @@ hal_gpio_init_in(int pin, gpio_pull_t pull)
}
/**
- * gpio init out
- *
- * Initialize the specified pin as an output, setting the pin to the specified
- * value.
- *
+ * gpio init out
+ *
+ * Initialize the specified pin as an output, setting the pin to the specified
+ * value.
+ *
* @param pin Pin number to set as output
* @param val Value to set pin
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int hal_gpio_init_out(int pin, int val)
{
@@ -363,11 +363,11 @@ int hal_gpio_init_out(int pin, int val)
}
/**
- * gpio set
- *
- * Sets specified pin to 1 (high)
- *
- * @param pin
+ * gpio set
+ *
+ * Sets specified pin to 1 (high)
+ *
+ * @param pin
*/
void hal_gpio_set(int pin)
{
@@ -376,10 +376,10 @@ void hal_gpio_set(int pin)
/**
* gpio clear
- *
- * Sets specified pin to 0 (low).
- *
- * @param pin
+ *
+ * Sets specified pin to 0 (low).
+ *
+ * @param pin
*/
void hal_gpio_clear(int pin)
{
@@ -387,10 +387,10 @@ void hal_gpio_clear(int pin)
}
/**
- * gpio write
- *
+ * gpio write
+ *
* Write a value (either high or low) to the specified pin.
- *
+ *
* @param pin Pin to set
* @param val Value to set pin (0:low 1:high)
*/
@@ -404,12 +404,12 @@ void hal_gpio_write(int pin, int val)
}
/**
- * gpio read
- *
- * Reads the specified pin.
- *
+ * gpio read
+ *
+ * Reads the specified pin.
+ *
* @param pin Pin number to read
- *
+ *
* @return int 0: low, 1: high
*/
int hal_gpio_read(int pin)
@@ -418,33 +418,33 @@ int hal_gpio_read(int pin)
}
/**
- * gpio toggle
- *
+ * gpio toggle
+ *
* Toggles the specified pin
- *
+ *
* @param pin Pin number to toggle
+ *
+ * @return current pin state int 0: low, 1: high
*/
-void hal_gpio_toggle(int pin)
+int hal_gpio_toggle(int pin)
{
- if (hal_gpio_read(pin)) {
- hal_gpio_clear(pin);
- } else {
- hal_gpio_set(pin);
- }
+ int pin_state = (hal_gpio_read(pin) != 1);
+ hal_gpio_write(pin, pin_state);
+ return pin_state;
}
/**
* gpio irq init
- *
- * Initialize an external interrupt on a gpio pin
- *
+ *
+ * Initialize an external interrupt on a gpio pin
+ *
* @param pin Pin number to enable gpio.
* @param handler Interrupt handler
* @param arg Argument to pass to interrupt handler
* @param trig Trigger mode of interrupt
* @param pull Push/pull mode of input.
- *
- * @return int
+ *
+ * @return int
*/
int
hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
@@ -516,13 +516,13 @@ hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
/**
* gpio irq release
- *
- * No longer interrupt when something occurs on the pin. NOTE: this function
- * does not change the GPIO push/pull setting nor does it change the
- * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
- * setting for the irq.
- *
- * @param pin
+ *
+ * No longer interrupt when something occurs on the pin. NOTE: this function
+ * does not change the GPIO push/pull setting nor does it change the
+ * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
+ * setting for the irq.
+ *
+ * @param pin
*/
void
hal_gpio_irq_release(int pin)
@@ -548,11 +548,11 @@ hal_gpio_irq_release(int pin)
}
/**
- * gpio irq enable
- *
- * Enable the irq on the specified pin
- *
- * @param pin
+ * gpio irq enable
+ *
+ * Enable the irq on the specified pin
+ *
+ * @param pin
*/
void
hal_gpio_irq_enable(int pin)
@@ -573,9 +573,9 @@ hal_gpio_irq_enable(int pin)
/**
* gpio irq disable
- *
- *
- * @param pin
+ *
+ *
+ * @param pin
*/
void
hal_gpio_irq_disable(int pin)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/274da326/hw/mcu/nordic/nrf52xxx/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_gpio.c b/hw/mcu/nordic/nrf52xxx/src/hal_gpio.c
index c1c77a9..3619753 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_gpio.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_gpio.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -26,28 +26,28 @@
/* XXX: Notes
* 1) Right now, we are not disabling the NVIC interrupt source; we only
* disable the external interrupt from occurring. Dont think either way
- * to do it is an issue... when we release we may want to disable the NVIC
- *
+ * to do it is an issue... when we release we may want to disable the NVIC
+ *
* 2) investigate how thread safe these routines are. HAL_GPIO_Init, for
* example. Looks like if it gets interrupted while doing config an error
- * may occur. Read/modify write could cause screw-ups.
- *
- * 3) Currently, this code does not change the interrupt priority of the
- * external interrupt vectors in the NVIC. The application developer must
- * decide on the priority level for each external interrupt and program that
- * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
- *
- * 4) The code probably does not handle "re-purposing" gpio very well.
- * "Re-purposing" means changing a gpio from input to output, or calling
- * gpio_init_in and expecting previously enabled interrupts to be stopped.
- *
- * 5) Possbily add access to HAL_GPIO_DeInit.
+ * may occur. Read/modify write could cause screw-ups.
+ *
+ * 3) Currently, this code does not change the interrupt priority of the
+ * external interrupt vectors in the NVIC. The application developer must
+ * decide on the priority level for each external interrupt and program that
+ * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
+ *
+ * 4) The code probably does not handle "re-purposing" gpio very well.
+ * "Re-purposing" means changing a gpio from input to output, or calling
+ * gpio_init_in and expecting previously enabled interrupts to be stopped.
+ *
+ * 5) Possbily add access to HAL_GPIO_DeInit.
*/
-/*
+/*
* GPIO pin mapping
- *
- */
+ *
+ */
#define GPIO_INDEX(pin) (pin)
#define GPIO_MASK(pin) (1 << GPIO_INDEX(pin))
@@ -76,11 +76,11 @@ struct ext_irqs ext_irq_counts;
#if 0
/**
- * ext irq handler
- *
- * Handles the gpio interrupt attached to a gpio pin.
- *
- * @param index
+ * ext irq handler
+ *
+ * Handles the gpio interrupt attached to a gpio pin.
+ *
+ * @param index
*/
static void
ext_irq_handler(int index)
@@ -128,9 +128,9 @@ ext_irq3(void)
/**
* ext irq4
- *
+ *
* External interrupt handler for external interrupt 4.
- *
+ *
*/
static void
ext_irq4(void)
@@ -140,10 +140,10 @@ ext_irq4(void)
}
/**
- * ext irq9_5
- *
- * External interrupt handler for irqs 9 through 5.
- *
+ * ext irq9_5
+ *
+ * External interrupt handler for irqs 9 through 5.
+ *
*/
static void
ext_irq9_5(void)
@@ -157,10 +157,10 @@ ext_irq9_5(void)
}
/**
- * ext irq15_10
- *
- * External interrupt handler for irqs 15 through 10.
- *
+ * ext irq15_10
+ *
+ * External interrupt handler for irqs 15 through 10.
+ *
*/
static void
ext_irq15_10(void)
@@ -174,13 +174,13 @@ ext_irq15_10(void)
}
/**
- * hal gpio clk enable
- *
- * Enable the port peripheral clock
- *
- * @param port_idx
+ * hal gpio clk enable
+ *
+ * Enable the port peripheral clock
+ *
+ * @param port_idx
*/
-static void
+static void
hal_gpio_clk_enable(uint32_t port_idx)
{
switch (port_idx) {
@@ -236,14 +236,14 @@ hal_gpio_clk_enable(uint32_t port_idx)
}
/**
- * hal gpio pin to irq
- *
- * Converts the logical pin number to the IRQ number associated with the
- * external interrupt for that particular GPIO.
- *
- * @param pin
- *
- * @return IRQn_Type
+ * hal gpio pin to irq
+ *
+ * Converts the logical pin number to the IRQ number associated with the
+ * external interrupt for that particular GPIO.
+ *
+ * @param pin
+ *
+ * @return IRQn_Type
*/
static IRQn_Type
hal_gpio_pin_to_irq(int pin)
@@ -306,14 +306,14 @@ hal_gpio_set_nvic(IRQn_Type irqn)
}
/**
- * gpio init in
- *
- * Initializes the specified pin as an input
- *
+ * gpio init in
+ *
+ * Initializes the specified pin as an input
+ *
* @param pin Pin number to set as input
* @param pull pull type
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int
hal_gpio_init_in(int pin, gpio_pull_t pull)
@@ -340,15 +340,15 @@ hal_gpio_init_in(int pin, gpio_pull_t pull)
}
/**
- * gpio init out
- *
- * Initialize the specified pin as an output, setting the pin to the specified
- * value.
- *
+ * gpio init out
+ *
+ * Initialize the specified pin as an output, setting the pin to the specified
+ * value.
+ *
* @param pin Pin number to set as output
* @param val Value to set pin
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int hal_gpio_init_out(int pin, int val)
{
@@ -363,11 +363,11 @@ int hal_gpio_init_out(int pin, int val)
}
/**
- * gpio set
- *
- * Sets specified pin to 1 (high)
- *
- * @param pin
+ * gpio set
+ *
+ * Sets specified pin to 1 (high)
+ *
+ * @param pin
*/
void hal_gpio_set(int pin)
{
@@ -376,10 +376,10 @@ void hal_gpio_set(int pin)
/**
* gpio clear
- *
- * Sets specified pin to 0 (low).
- *
- * @param pin
+ *
+ * Sets specified pin to 0 (low).
+ *
+ * @param pin
*/
void hal_gpio_clear(int pin)
{
@@ -387,10 +387,10 @@ void hal_gpio_clear(int pin)
}
/**
- * gpio write
- *
+ * gpio write
+ *
* Write a value (either high or low) to the specified pin.
- *
+ *
* @param pin Pin to set
* @param val Value to set pin (0:low 1:high)
*/
@@ -404,12 +404,12 @@ void hal_gpio_write(int pin, int val)
}
/**
- * gpio read
- *
- * Reads the specified pin.
- *
+ * gpio read
+ *
+ * Reads the specified pin.
+ *
* @param pin Pin number to read
- *
+ *
* @return int 0: low, 1: high
*/
int hal_gpio_read(int pin)
@@ -418,33 +418,33 @@ int hal_gpio_read(int pin)
}
/**
- * gpio toggle
- *
+ * gpio toggle
+ *
* Toggles the specified pin
- *
+ *
* @param pin Pin number to toggle
+ *
+ * @return current pin state int 0: low, 1: high
*/
-void hal_gpio_toggle(int pin)
+int hal_gpio_toggle(int pin)
{
- if (hal_gpio_read(pin)) {
- hal_gpio_clear(pin);
- } else {
- hal_gpio_set(pin);
- }
+ int pin_state = (hal_gpio_read(pin) != 1);
+ hal_gpio_write(pin, pin_state);
+ return pin_state;
}
/**
* gpio irq init
- *
- * Initialize an external interrupt on a gpio pin
- *
+ *
+ * Initialize an external interrupt on a gpio pin
+ *
* @param pin Pin number to enable gpio.
* @param handler Interrupt handler
* @param arg Argument to pass to interrupt handler
* @param trig Trigger mode of interrupt
* @param pull Push/pull mode of input.
- *
- * @return int
+ *
+ * @return int
*/
int
hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
@@ -516,13 +516,13 @@ hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
/**
* gpio irq release
- *
- * No longer interrupt when something occurs on the pin. NOTE: this function
- * does not change the GPIO push/pull setting nor does it change the
- * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
- * setting for the irq.
- *
- * @param pin
+ *
+ * No longer interrupt when something occurs on the pin. NOTE: this function
+ * does not change the GPIO push/pull setting nor does it change the
+ * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
+ * setting for the irq.
+ *
+ * @param pin
*/
void
hal_gpio_irq_release(int pin)
@@ -548,11 +548,11 @@ hal_gpio_irq_release(int pin)
}
/**
- * gpio irq enable
- *
- * Enable the irq on the specified pin
- *
- * @param pin
+ * gpio irq enable
+ *
+ * Enable the irq on the specified pin
+ *
+ * @param pin
*/
void
hal_gpio_irq_enable(int pin)
@@ -573,9 +573,9 @@ hal_gpio_irq_enable(int pin)
/**
* gpio irq disable
- *
- *
- * @param pin
+ *
+ *
+ * @param pin
*/
void
hal_gpio_irq_disable(int pin)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/274da326/hw/mcu/stm/stm32f4xx/src/hal_gpio.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_gpio.c b/hw/mcu/stm/stm32f4xx/src/hal_gpio.c
index 82b5ba1..56b457e 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_gpio.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_gpio.c
@@ -6,7 +6,7 @@
* to you 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,
@@ -27,25 +27,25 @@
/* XXX: Notes
* 1) Right now, we are not disabling the NVIC interrupt source; we only
* disable the external interrupt from occurring. Dont think either way
- * to do it is an issue... when we release we may want to disable the NVIC
- *
+ * to do it is an issue... when we release we may want to disable the NVIC
+ *
* 2) investigate how thread safe these routines are. HAL_GPIO_Init, for
* example. Looks like if it gets interrupted while doing config an error
- * may occur. Read/modify write could cause screw-ups.
- *
- * 3) Currently, this code does not change the interrupt priority of the
- * external interrupt vectors in the NVIC. The application developer must
- * decide on the priority level for each external interrupt and program that
- * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
- *
- * 4) The code probably does not handle "re-purposing" gpio very well.
- * "Re-purposing" means changing a gpio from input to output, or calling
- * gpio_init_in and expecting previously enabled interrupts to be stopped.
- *
- * 5) Possbily add access to HAL_GPIO_DeInit.
+ * may occur. Read/modify write could cause screw-ups.
+ *
+ * 3) Currently, this code does not change the interrupt priority of the
+ * external interrupt vectors in the NVIC. The application developer must
+ * decide on the priority level for each external interrupt and program that
+ * by using the CMSIS NVIC API (NVIC_SetPriority and NVIC_SetPriorityGrouping)
+ *
+ * 4) The code probably does not handle "re-purposing" gpio very well.
+ * "Re-purposing" means changing a gpio from input to output, or calling
+ * gpio_init_in and expecting previously enabled interrupts to be stopped.
+ *
+ * 5) Possbily add access to HAL_GPIO_DeInit.
*/
-/*
+/*
* GPIO pin mapping
*
* The stm32F4xx processors have 16 gpio pins per port. We map the logical pin
@@ -53,15 +53,15 @@
* Port A: PA0-PA15 map to pins 0 - 15.
* Port B: PB0-PB15 map to pins 16 - 31.
* Port C: PC0-PC15 map to pins 32 - 47.
- *
+ *
* To convert a gpio to pin number, do the following:
* - Convert port label to its numeric value (A=0, B=1, C=2, etc).
* - Multiply by 16.
* - Add port pin number.
- *
+ *
* Ex: PD11 = (4 * 16) + 11 = 75.
* PA0 = (0 * 16) + 0 = 0
- */
+ */
#define GPIO_INDEX(pin) ((pin) & 0x0F)
#define GPIO_PORT(pin) (((pin) >> 4) & 0x0F)
#define GPIO_MASK(pin) (1 << GPIO_INDEX(pin))
@@ -133,11 +133,11 @@ struct ext_irqs
struct ext_irqs ext_irq_counts;
/**
- * ext irq handler
- *
- * Handles the gpio interrupt attached to a gpio pin.
- *
- * @param index
+ * ext irq handler
+ *
+ * Handles the gpio interrupt attached to a gpio pin.
+ *
+ * @param index
*/
static void
ext_irq_handler(int index)
@@ -185,9 +185,9 @@ ext_irq3(void)
/**
* ext irq4
- *
+ *
* External interrupt handler for external interrupt 4.
- *
+ *
*/
static void
ext_irq4(void)
@@ -197,10 +197,10 @@ ext_irq4(void)
}
/**
- * ext irq9_5
- *
- * External interrupt handler for irqs 9 through 5.
- *
+ * ext irq9_5
+ *
+ * External interrupt handler for irqs 9 through 5.
+ *
*/
static void
ext_irq9_5(void)
@@ -214,10 +214,10 @@ ext_irq9_5(void)
}
/**
- * ext irq15_10
- *
- * External interrupt handler for irqs 15 through 10.
- *
+ * ext irq15_10
+ *
+ * External interrupt handler for irqs 15 through 10.
+ *
*/
static void
ext_irq15_10(void)
@@ -231,13 +231,13 @@ ext_irq15_10(void)
}
/**
- * hal gpio clk enable
- *
- * Enable the port peripheral clock
- *
- * @param port_idx
+ * hal gpio clk enable
+ *
+ * Enable the port peripheral clock
+ *
+ * @param port_idx
*/
-static void
+static void
hal_gpio_clk_enable(uint32_t port_idx)
{
switch (port_idx) {
@@ -293,14 +293,14 @@ hal_gpio_clk_enable(uint32_t port_idx)
}
/**
- * hal gpio pin to irq
- *
- * Converts the logical pin number to the IRQ number associated with the
- * external interrupt for that particular GPIO.
- *
- * @param pin
- *
- * @return IRQn_Type
+ * hal gpio pin to irq
+ *
+ * Converts the logical pin number to the IRQ number associated with the
+ * external interrupt for that particular GPIO.
+ *
+ * @param pin
+ *
+ * @return IRQn_Type
*/
static IRQn_Type
hal_gpio_pin_to_irq(int pin)
@@ -361,13 +361,13 @@ hal_gpio_set_nvic(IRQn_Type irqn)
/**
* hal gpio init
- *
- * Called to initialize a gpio.
- *
- * @param pin
- * @param cfg
- *
- * @return int
+ *
+ * Called to initialize a gpio.
+ *
+ * @param pin
+ * @param cfg
+ *
+ * @return int
*/
static int
hal_gpio_init(int pin, GPIO_InitTypeDef *cfg)
@@ -394,14 +394,14 @@ hal_gpio_init(int pin, GPIO_InitTypeDef *cfg)
}
/**
- * gpio init in
- *
- * Initializes the specified pin as an input
- *
+ * gpio init in
+ *
+ * Initializes the specified pin as an input
+ *
* @param pin Pin number to set as input
* @param pull pull type
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int
hal_gpio_init_in(int pin, gpio_pull_t pull)
@@ -417,15 +417,15 @@ hal_gpio_init_in(int pin, gpio_pull_t pull)
}
/**
- * gpio init out
- *
- * Initialize the specified pin as an output, setting the pin to the specified
- * value.
- *
+ * gpio init out
+ *
+ * Initialize the specified pin as an output, setting the pin to the specified
+ * value.
+ *
* @param pin Pin number to set as output
* @param val Value to set pin
- *
- * @return int 0: no error; -1 otherwise.
+ *
+ * @return int 0: no error; -1 otherwise.
*/
int hal_gpio_init_out(int pin, int val)
{
@@ -460,11 +460,11 @@ hal_gpio_init_af(int pin, uint8_t af_type, enum gpio_pull pull)
}
/**
- * gpio set
- *
- * Sets specified pin to 1 (high)
- *
- * @param pin
+ * gpio set
+ *
+ * Sets specified pin to 1 (high)
+ *
+ * @param pin
*/
void hal_gpio_set(int pin)
{
@@ -478,10 +478,10 @@ void hal_gpio_set(int pin)
/**
* gpio clear
- *
- * Sets specified pin to 0 (low).
- *
- * @param pin
+ *
+ * Sets specified pin to 0 (low).
+ *
+ * @param pin
*/
void hal_gpio_clear(int pin)
{
@@ -494,10 +494,10 @@ void hal_gpio_clear(int pin)
}
/**
- * gpio write
- *
+ * gpio write
+ *
* Write a value (either high or low) to the specified pin.
- *
+ *
* @param pin Pin to set
* @param val Value to set pin (0:low 1:high)
*/
@@ -511,12 +511,12 @@ void hal_gpio_write(int pin, int val)
}
/**
- * gpio read
- *
- * Reads the specified pin.
- *
+ * gpio read
+ *
+ * Reads the specified pin.
+ *
* @param pin Pin number to read
- *
+ *
* @return int 0: low, 1: high
*/
int hal_gpio_read(int pin)
@@ -530,33 +530,33 @@ int hal_gpio_read(int pin)
}
/**
- * gpio toggle
- *
+ * gpio toggle
+ *
* Toggles the specified pin
- *
+ *
* @param pin Pin number to toggle
+ *
+ * @return current pin state int 0: low 1 : high
*/
-void hal_gpio_toggle(int pin)
+int hal_gpio_toggle(int pin)
{
- if (hal_gpio_read(pin)) {
- hal_gpio_clear(pin);
- } else {
- hal_gpio_set(pin);
- }
+ int pin_state = (hal_gpio_read(pin) != 1);
+ hal_gpio_write(pin, pin_state);
+ return pin_state;
}
/**
* gpio irq init
- *
- * Initialize an external interrupt on a gpio pin
- *
+ *
+ * Initialize an external interrupt on a gpio pin
+ *
* @param pin Pin number to enable gpio.
* @param handler Interrupt handler
* @param arg Argument to pass to interrupt handler
* @param trig Trigger mode of interrupt
* @param pull Push/pull mode of input.
- *
- * @return int
+ *
+ * @return int
*/
int
hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
@@ -623,13 +623,13 @@ hal_gpio_irq_init(int pin, gpio_irq_handler_t handler, void *arg,
/**
* gpio irq release
- *
- * No longer interrupt when something occurs on the pin. NOTE: this function
- * does not change the GPIO push/pull setting nor does it change the
- * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
- * setting for the irq.
- *
- * @param pin
+ *
+ * No longer interrupt when something occurs on the pin. NOTE: this function
+ * does not change the GPIO push/pull setting nor does it change the
+ * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable
+ * setting for the irq.
+ *
+ * @param pin
*/
void
hal_gpio_irq_release(int pin)
@@ -651,11 +651,11 @@ hal_gpio_irq_release(int pin)
}
/**
- * gpio irq enable
- *
- * Enable the irq on the specified pin
- *
- * @param pin
+ * gpio irq enable
+ *
+ * Enable the irq on the specified pin
+ *
+ * @param pin
*/
void
hal_gpio_irq_enable(int pin)
@@ -672,9 +672,9 @@ hal_gpio_irq_enable(int pin)
/**
* gpio irq disable
- *
- *
- * @param pin
+ *
+ *
+ * @param pin
*/
void
hal_gpio_irq_disable(int pin)