mirror of https://github.com/ARMmbed/mbed-os.git
gpio and pinmap - asserts for NC as parameters (not init), abort retarget
- retarget - abort - calls mbed_die - asserts added to gpio mbed hal for all targetspull/316/head
parent
4c61464ee7
commit
09fe00f041
|
@ -17,7 +17,8 @@
|
|||
#include "error.h"
|
||||
|
||||
void pinmap_pinout(PinName pin, const PinMap *map) {
|
||||
if (pin == NC) return;
|
||||
if (pin == NC)
|
||||
return;
|
||||
|
||||
while (map->pin != NC) {
|
||||
if (map->pin == pin) {
|
||||
|
@ -33,11 +34,14 @@ void pinmap_pinout(PinName pin, const PinMap *map) {
|
|||
|
||||
uint32_t pinmap_merge(uint32_t a, uint32_t b) {
|
||||
// both are the same (inc both NC)
|
||||
if (a == b) return a;
|
||||
if (a == b)
|
||||
return a;
|
||||
|
||||
// one (or both) is not connected
|
||||
if (a == (uint32_t)NC) return b;
|
||||
if (b == (uint32_t)NC) return a;
|
||||
if (a == (uint32_t)NC)
|
||||
return b;
|
||||
if (b == (uint32_t)NC)
|
||||
return a;
|
||||
|
||||
// mis-match error case
|
||||
error("pinmap mis-match");
|
||||
|
|
|
@ -396,6 +396,13 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
|
|||
|
||||
#endif
|
||||
|
||||
#include "mbed_interface.h"
|
||||
|
||||
extern "C" void abort(void) {
|
||||
mbed_die();
|
||||
while(1);
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
// mbed_main is a function that is called before main()
|
||||
// mbed_sdk_init() is also a function that is called before main(), but unlike
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
pin_function(pin, 1);
|
||||
return 1 << ((pin & 0x7F) >> 2);
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
if(pin == (PinName)NC)
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
|
||||
|
@ -42,9 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -41,8 +42,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
|
||||
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
|
||||
|
@ -31,8 +30,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);
|
||||
|
||||
// pin pullup bits: [1:0] -> 11 = (0x3)
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
pin_function(pin, 1);
|
||||
return 1 << ((pin & 0x7F) >> 2);
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
|
||||
|
@ -42,9 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -40,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
|
||||
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
|
||||
|
@ -31,8 +30,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
__IO uint32_t* pin_pcr = (__IO uint32_t*)(PORTA_BASE + pin);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "fsl_port_hal.h"
|
||||
|
@ -20,6 +21,7 @@
|
|||
#include "fsl_sim_hal.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t pin_num = pin & 0xFF;
|
||||
|
||||
pin_function(pin, (int)kPortMuxAsGpio);
|
||||
|
@ -27,10 +29,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pinName = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pinName = pin;
|
||||
uint32_t port = pin >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin_num = pin & 0xFF;
|
||||
clock_hal_set_gate(kSimClockModulePORT, port, true);
|
||||
|
@ -42,8 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin_num = obj->pinName & 0xFF;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "fsl_gpio_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -27,8 +28,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pinName & 0xFF;
|
||||
|
||||
|
@ -36,8 +36,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pinName & 0xFF;
|
||||
|
||||
|
|
|
@ -13,25 +13,20 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
#include "fsl_clock_manager.h"
|
||||
#include "fsl_port_hal.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
clock_manager_set_gate(kClockModulePORT, pin >> GPIO_PORT_SHIFT, true);
|
||||
port_hal_mux_control(pin >> GPIO_PORT_SHIFT, pin & 0xFF, (port_mux_t)function);
|
||||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t instance = pin >> GPIO_PORT_SHIFT;
|
||||
uint32_t pinName = pin & 0xFF;
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
if(pin == (PinName)NC)
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = (1ul << pin);
|
||||
|
||||
obj->reg_set = &NRF_GPIO->OUTSET;
|
||||
|
@ -34,22 +35,21 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
|
||||
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
|
||||
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
|
||||
break;
|
||||
break;
|
||||
case PIN_OUTPUT:
|
||||
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
|
||||
NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
|
||||
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
|
||||
| (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
|
||||
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
|
||||
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -40,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -20,10 +21,10 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
|
||||
NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_PULL_Msk;
|
||||
NRF_GPIO->PIN_CNF[pin_number] |= (mode<<GPIO_PIN_CNF_PULL_Pos);
|
||||
NRF_GPIO->PIN_CNF[pin_number] |= (mode << GPIO_PIN_CNF_PULL_Pos);
|
||||
}
|
||||
|
|
|
@ -13,20 +13,22 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
/* Enable AHB clock to the GPIO and IOCON domain. */
|
||||
LPC_SYSCON->SYSAHBCLKCTRL |= ((1 << 16) | (1 << 6));
|
||||
return (1UL << ((int)pin >> PIN_SHIFT & 0x1F));
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)(pin >> PORT_SHIFT);
|
||||
|
@ -42,9 +44,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,9 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,15 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (uint32_t)NC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + (pin & 0x1FF));
|
||||
|
||||
// pin function bits: [2:0] -> 111 = (0x7)
|
||||
|
@ -29,11 +26,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
if ((pin == P0_4) || (pin == P0_5)) {
|
||||
// The true open-drain pins PIO0_4 and PIO0_5 can be configured for different I2C-bus speeds.
|
||||
return;
|
||||
|
|
|
@ -13,10 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
int f = ((pin == P0_11) || (pin == P0_12) ||
|
||||
(pin == P0_13) || (pin == P0_14)) ? (1) : (0);
|
||||
pin_function(pin, f);
|
||||
|
@ -25,10 +27,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
|
||||
|
@ -44,9 +46,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,9 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,9 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -20,27 +21,27 @@
|
|||
#define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60)
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
assert(pin != (PinName)NC);
|
||||
if (pin == (PinName)NC) return;
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
|
||||
__IO uint32_t *reg = (pin_number < 32) ?
|
||||
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
|
||||
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
|
||||
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
|
||||
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
|
||||
|
||||
// pin function bits: [2:0] -> 111 = (0x7)
|
||||
*reg = (*reg & ~0x7) | (function & 0x7);
|
||||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
|
||||
|
||||
__IO uint32_t *reg = (pin_number < 32) ?
|
||||
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
|
||||
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
|
||||
(__IO uint32_t*)(LPC_IOCON0_BASE + 4 * pin_number) :
|
||||
(__IO uint32_t*)(LPC_IOCON1_BASE + 4 * (pin_number - 32));
|
||||
uint32_t tmp = *reg;
|
||||
|
||||
// pin mode bits: [4:3] -> 11000 = (0x3 << 3)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "reserved_pins.h"
|
||||
|
@ -20,25 +21,26 @@
|
|||
static const PinName reserved_pins[] = TARGET_RESERVED_PINS;
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
// PIO default value of following ports are not same as others
|
||||
unsigned i;
|
||||
int f = 0;
|
||||
|
||||
for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++)
|
||||
for (i = 0; i < sizeof(reserved_pins) / sizeof(PinName); i ++) {
|
||||
if (pin == reserved_pins[i]) {
|
||||
f = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
pin_function(pin, f);
|
||||
return ((pin & 0x0F00) >> 8);
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
LPC_GPIO_TypeDef *port_reg = ((LPC_GPIO_TypeDef *) (LPC_GPIO0_BASE + (((pin & 0xF000) >> PORT_SHIFT) * 0x10000)));
|
||||
|
||||
obj->reg_mask_read = &port_reg->MASKED_ACCESS[1 << gpio_set(pin)];
|
||||
|
@ -51,12 +53,14 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
int pin_number = ((obj->pin & 0x0F00) >> 8);
|
||||
switch (direction) {
|
||||
case PIN_INPUT : *obj->reg_dir &= ~(1 << pin_number); break;
|
||||
case PIN_OUTPUT: *obj->reg_dir |= (1 << pin_number); break;
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~(1 << pin_number);
|
||||
break;
|
||||
case PIN_OUTPUT:
|
||||
*obj->reg_dir |= (1 << pin_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -28,8 +30,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
uint32_t pin_number = ((obj->pin & 0x0F00) >> 8);
|
||||
if (value)
|
||||
*obj->reg_write |= (1 << pin_number);
|
||||
|
@ -38,8 +39,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_mask_read) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (uint32_t)NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t offset = (uint32_t)pin & 0xff;
|
||||
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset);
|
||||
|
||||
|
@ -27,10 +27,9 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t offset = (uint32_t)pin & 0xff;
|
||||
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
|
||||
uint32_t drain = ((uint32_t)mode & (uint32_t)OpenDrain) >> 2;
|
||||
|
||||
__IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset);
|
||||
uint32_t tmp = *reg;
|
||||
|
|
|
@ -13,10 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
int f = ((pin == P0_11) || (pin == P0_12) ||
|
||||
(pin == P0_13) || (pin == P0_14)) ? (1) : (0);
|
||||
pin_function(pin, f);
|
||||
|
@ -25,10 +27,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
|
||||
|
@ -44,10 +46,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
|
||||
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
break;
|
||||
case PIN_OUTPUT:
|
||||
*obj->reg_dir |= obj->mask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -40,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -20,7 +21,7 @@
|
|||
#define LPC_IOCON1_BASE (LPC_IOCON_BASE + 0x60)
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (uint32_t)NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
|
||||
|
@ -33,7 +34,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
LPC_SYSCON->SYSAHBCLKCTRL0 |= (0xFUL << 13);
|
||||
return (1UL << ((int)pin & 0x1f));
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
unsigned int port = (unsigned int)(pin >> 5);
|
||||
|
@ -41,9 +43,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
|
@ -41,8 +42,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -20,7 +21,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
if ((pin == P0_22) || (pin == P0_23)) {
|
||||
// The true open-drain pins PIO0_22 and PIO0_23 can be configured for different I2C-bus speeds.
|
||||
|
|
|
@ -13,21 +13,23 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
pin_function(pin, 0);
|
||||
return (1 << ((int)pin & 0x1F));
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
obj->pin = pin;
|
||||
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *) ((int)pin & ~0x1F);
|
||||
LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *)((int)pin & ~0x1F);
|
||||
obj->reg_set = &port_reg->FIOSET;
|
||||
obj->reg_clr = &port_reg->FIOCLR;
|
||||
obj->reg_in = &port_reg->FIOPIN;
|
||||
|
@ -39,10 +41,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
|
||||
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
break;
|
||||
case PIN_OUTPUT:
|
||||
*obj->reg_dir |= obj->mask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -40,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
|
||||
int index = pin_number >> 4;
|
||||
int offset = (pin_number & 0xF) << 1;
|
||||
|
@ -28,7 +29,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
|
||||
int index = pin_number >> 5;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,8 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -40,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
|
||||
int index = pin_number >> 4;
|
||||
|
@ -28,15 +29,13 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
|
||||
assert((pin != (PinName)NC) && (mode != OpenDrain));
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin - (uint32_t)P0_0;
|
||||
int index = pin_number >> 5;
|
||||
int offset = pin_number & 0x1F;
|
||||
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
|
||||
|
||||
if (mode == OpenDrain) error("OpenDrain not supported on LPC2368");
|
||||
|
||||
|
||||
if (!drain) {
|
||||
index = pin_number >> 4;
|
||||
offset = (pin_number & 0xF) << 1;
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
pin_function(pin, 0);
|
||||
return (1 << ((int)pin & 0x1F));
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
LPC_GPIO_TypeDef *port_reg = (LPC_GPIO_TypeDef *) ((int)(LPC_GPIO0_BASE+pin) & ~0x1F);
|
||||
|
@ -41,8 +43,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,9 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
__IO uint32_t *reg = (__IO uint32_t*) (LPC_IOCON_BASE + 4 * pin);
|
||||
|
||||
// pin function bits: [2:0] -> 111 = (0x7)
|
||||
|
@ -26,7 +26,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (PinName)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;
|
||||
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
*
|
||||
* Ported to NXP LPC43XX by Micromint USA <support@micromint.com>
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
int f = 0;
|
||||
unsigned int port = (unsigned int)MBED_GPIO_PORT(pin);
|
||||
|
||||
|
@ -29,10 +31,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
LPC_GPIO_T *port_reg = (LPC_GPIO_T *) (LPC_GPIO_PORT_BASE);
|
||||
|
@ -49,11 +51,13 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT : *obj->reg_dir &= ~obj->mask; break;
|
||||
case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break;
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
break;
|
||||
case PIN_OUTPUT:
|
||||
*obj->reg_dir |= obj->mask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,9 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,8 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,12 @@
|
|||
*
|
||||
* Ported to NXP LPC43XX by Micromint USA <support@micromint.com>
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (uint32_t)NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
__IO uint32_t *reg = (__IO uint32_t*) MBED_SCU_REG(pin);
|
||||
|
||||
|
@ -28,9 +29,7 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
|
||||
if (mode == OpenDrain) error("OpenDrain not supported on LPC43XX");
|
||||
assert((pin != (PinName)NC) && (mode == OpenDrain));
|
||||
|
||||
__IO uint32_t *reg = (__IO uint32_t*) MBED_SCU_REG(pin);
|
||||
uint32_t tmp = *reg;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
|
@ -40,10 +41,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
obj->reg_set = &LPC_GPIO_PORT->SET0;
|
||||
|
@ -57,9 +58,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
*obj->reg_dir &= ~obj->mask;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,9 +33,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,9 +41,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -30,8 +31,8 @@ void pin_function(PinName pin, int function) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
if ((pin == 10) || (pin == 11)) {
|
||||
// True open-drain pins can be configured for different I2C-bus speeds
|
||||
return;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,9 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
}
|
||||
|
@ -60,8 +59,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "device.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -66,8 +67,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t otype = STM_PIN_OTYPE(data);
|
||||
|
@ -104,15 +104,14 @@ void pin_function(PinName pin, int data) {
|
|||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -122,7 +121,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "device.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -75,8 +76,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (input, output, alternate function or analog) + output speed + AF
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
@ -111,17 +111,16 @@ void pin_function(PinName pin, int data) {
|
|||
}
|
||||
if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
assert(pin != (PinName)NC);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
if (pin == NC) return;
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -131,32 +130,31 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure open-drain and pull-up/down
|
||||
switch (mode) {
|
||||
case PullNone:
|
||||
return;
|
||||
case PullUp:
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
break;
|
||||
case PullDown:
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
break;
|
||||
case OpenDrain:
|
||||
if (pin_index < 8) {
|
||||
if ((gpio->CRL & (0x03 << (pin_index * 4))) > 0) { // MODE bits = Output mode
|
||||
gpio->CRL |= (0x04 << (pin_index * 4)); // Set open-drain
|
||||
case PullNone:
|
||||
return;
|
||||
case PullUp:
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
break;
|
||||
case PullDown:
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
|
||||
break;
|
||||
case OpenDrain:
|
||||
if (pin_index < 8) {
|
||||
if ((gpio->CRL & (0x03 << (pin_index * 4))) > 0) { // MODE bits = Output mode
|
||||
gpio->CRL |= (0x04 << (pin_index * 4)); // Set open-drain
|
||||
}
|
||||
} else {
|
||||
if ((gpio->CRH & (0x03 << ((pin_index % 8) * 4))) > 0) { // MODE bits = Output mode
|
||||
gpio->CRH |= (0x04 << ((pin_index % 8) * 4)); // Set open-drain
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((gpio->CRH & (0x03 << ((pin_index % 8) * 4))) > 0) { // MODE bits = Output mode
|
||||
gpio->CRH |= (0x04 << ((pin_index % 8) * 4)); // Set open-drain
|
||||
}
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Configure GPIO
|
||||
GPIO_InitStructure.GPIO_Pin = (uint16_t)(1 << pin_index);
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,9 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -59,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "device.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -71,7 +72,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
|
@ -108,14 +109,14 @@ void pin_function(PinName pin, int data) {
|
|||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
@ -126,7 +127,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -35,14 +36,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRRL;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
}
|
||||
|
@ -59,8 +59,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "device.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -74,7 +75,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
break;
|
||||
default:
|
||||
error("Pinmap error: wrong port number.");
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return gpio_add;
|
||||
}
|
||||
|
@ -83,8 +84,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
|
@ -113,15 +113,14 @@ void pin_function(PinName pin, int data) {
|
|||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -131,7 +130,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
}
|
||||
|
@ -59,8 +59,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -66,7 +67,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
|
@ -104,14 +105,14 @@ void pin_function(PinName pin, int data) {
|
|||
//}
|
||||
//if ((pin == PA_15) || (pin == PB_3) || (pin == PB_4)) {
|
||||
//
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_Out_PP, 0));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -58,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -77,8 +78,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (input, output, alternate function or analog) + output speed + AF
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
@ -120,10 +120,9 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
assert(pin != (PinName)NC);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
if (pin == NC) return;
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,9 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -59,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -67,8 +68,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t otype = STM_PIN_OTYPE(data);
|
||||
|
@ -111,8 +111,7 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -122,7 +121,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRRL;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -58,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -82,8 +83,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
|
@ -119,8 +119,7 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -130,7 +129,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -52,7 +53,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -64,6 +64,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,9 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -59,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -82,8 +83,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
|
@ -119,8 +119,7 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
|
@ -130,7 +129,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPD0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,14 +35,14 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
|
||||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
|
@ -51,7 +52,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRRL;
|
||||
|
@ -63,6 +63,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -58,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -66,7 +67,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
|
@ -110,7 +111,7 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
@ -121,7 +122,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
@ -34,8 +35,7 @@
|
|||
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
if (pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
pin_function(pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
|
||||
|
@ -43,6 +43,7 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -53,7 +54,6 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
|
||||
|
||||
// Fill GPIO object structure for future use
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
obj->reg_in = &gpio->IDR;
|
||||
obj->reg_set = &gpio->BSRR;
|
||||
|
@ -65,6 +65,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (direction == PIN_OUTPUT) {
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF));
|
||||
} else { // PIN_INPUT
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "cmsis.h"
|
||||
#include "PortNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
@ -48,8 +49,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value) {
|
||||
*obj->reg_set = obj->mask;
|
||||
} else {
|
||||
|
@ -58,8 +58,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "PortNames.h"
|
||||
#include "error.h"
|
||||
|
@ -71,7 +72,7 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx) {
|
|||
* Configure pin (mode, speed, output type and pull-up/pull-down)
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
// Get the pin informations
|
||||
uint32_t mode = STM_PIN_MODE(data);
|
||||
|
@ -115,7 +116,7 @@ void pin_function(PinName pin, int data) {
|
|||
* Configure pin pull-up/pull-down
|
||||
*/
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
@ -126,7 +127,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
// Configure pull-up/pull-down resistors
|
||||
uint32_t pupd = (uint32_t)mode;
|
||||
if (pupd > 2) pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
if (pupd > 2)
|
||||
pupd = 0; // Open-drain = No pull-up/No pull-down
|
||||
gpio->PUPDR &= (uint32_t)(~(GPIO_PUPDR_PUPDR0 << (pin_index * 2)));
|
||||
gpio->PUPDR |= (uint32_t)(pupd << (pin_index * 2));
|
||||
|
||||
|
|
|
@ -13,10 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "gpio_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
uint32_t gpio_set(PinName pin) {
|
||||
assert(pin != (PinName)NC);
|
||||
uint32_t port_index = (uint32_t) pin >> 4;
|
||||
|
||||
// Enable GPIO peripheral clock
|
||||
|
@ -27,10 +29,10 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
obj->pin = pin;
|
||||
obj->mask = gpio_set(pin);
|
||||
|
||||
uint32_t port_index = (uint32_t) pin >> 4;
|
||||
|
@ -47,6 +49,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
|||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
assert(obj->pin != (PinName)NC);
|
||||
switch (direction) {
|
||||
case PIN_INPUT :
|
||||
pin_function(obj->pin, STM_PIN_DATA(0, 0));
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef MBED_GPIO_OBJECT_H
|
||||
#define MBED_GPIO_OBJECT_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -32,8 +34,7 @@ typedef struct {
|
|||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
if (value)
|
||||
*obj->reg_set = obj->mask;
|
||||
else
|
||||
|
@ -41,8 +42,7 @@ static inline void gpio_write(gpio_t *obj, int value) {
|
|||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
if (obj->pin == (PinName)NC)
|
||||
return 0;
|
||||
assert(obj->pin != (PinName)NC);
|
||||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "pinmap.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -20,7 +21,7 @@
|
|||
* Set the pin into input, output, alternate function or analog mode
|
||||
*/
|
||||
void pin_function(PinName pin, int data) {
|
||||
if (pin == (uint32_t)NC) return;
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
int mode = STM_PIN_MODE(data);
|
||||
int func = STM_PIN_FUNC(data);
|
||||
|
@ -53,7 +54,7 @@ void pin_function(PinName pin, int data) {
|
|||
}
|
||||
|
||||
void pin_mode(PinName pin, PinMode mode) {
|
||||
if (pin == (uint32_t)NC) { return; }
|
||||
assert(pin != (PinName)NC);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
int port_index = pin_number >> 4;
|
||||
|
|
Loading…
Reference in New Issue