mirror of https://github.com/ARMmbed/mbed-os.git
Merge branch 'pinology' of https://github.com/PrzemekWirkus/mbed into PrzemekWirkus-pinology
Conflicts: libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/cmsis_nvic.cpull/868/head
commit
453e81fd4c
|
@ -58,15 +58,35 @@ public:
|
|||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalIn & operator[] (int index);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DigitalIn* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusIn(const BusIn&);
|
||||
|
|
|
@ -51,7 +51,6 @@ public:
|
|||
*/
|
||||
void write(int value);
|
||||
|
||||
|
||||
/** Read the value currently output on the bus
|
||||
*
|
||||
* @returns
|
||||
|
@ -73,12 +72,26 @@ public:
|
|||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
BusInOut& operator= (int v);
|
||||
BusInOut& operator= (BusInOut& rhs);
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalInOut& operator[] (int index);
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
|
@ -87,6 +100,12 @@ public:
|
|||
protected:
|
||||
DigitalInOut* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusInOut(const BusInOut&);
|
||||
|
|
|
@ -56,12 +56,26 @@ public:
|
|||
*/
|
||||
int read();
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
BusOut& operator= (int v);
|
||||
BusOut& operator= (BusOut& rhs);
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalOut& operator[] (int index);
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
|
@ -70,6 +84,12 @@ public:
|
|||
protected:
|
||||
DigitalOut* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusOut(const BusOut&);
|
||||
|
|
|
@ -80,6 +80,16 @@ public:
|
|||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** An operator shorthand for read()
|
||||
*/
|
||||
|
|
|
@ -85,6 +85,16 @@ public:
|
|||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
|
|
|
@ -77,6 +77,16 @@ public:
|
|||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
|
|
|
@ -20,14 +20,22 @@ namespace mbed {
|
|||
BusIn::BusIn(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusIn::BusIn(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +69,13 @@ void BusIn::mode(PinMode pull) {
|
|||
BusIn::operator int() {
|
||||
return read();
|
||||
}
|
||||
|
||||
DigitalIn& BusIn::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -20,14 +20,22 @@ namespace mbed {
|
|||
BusInOut::BusInOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusInOut::BusInOut(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +100,12 @@ BusInOut& BusInOut::operator= (BusInOut& rhs) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
DigitalInOut& BusInOut::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
BusInOut::operator int() {
|
||||
return read();
|
||||
}
|
||||
|
|
|
@ -20,14 +20,22 @@ namespace mbed {
|
|||
BusOut::BusOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusOut::BusOut(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +76,12 @@ BusOut& BusOut::operator= (BusOut& rhs) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
DigitalOut& BusOut::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
BusOut::operator int() {
|
||||
return read();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,12 @@ extern "C" {
|
|||
**/
|
||||
uint32_t gpio_set(PinName pin);
|
||||
|
||||
/* Checks if gpio object is connected (pin was not initialized with NC)
|
||||
* @param pin The pin to be set as GPIO
|
||||
* @return 0 if port is initialized with NC
|
||||
**/
|
||||
int gpio_is_connected(const gpio_t *obj);
|
||||
|
||||
/* GPIO object */
|
||||
void gpio_init(gpio_t *obj, PinName pin);
|
||||
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,7 @@ uint32_t gpio_set(PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_init(gpio_t *obj, PinName pin) {
|
||||
obj->pinName = pin;
|
||||
obj->pin = pin;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
|
@ -42,14 +42,14 @@ void gpio_init(gpio_t *obj, PinName pin) {
|
|||
}
|
||||
|
||||
void gpio_mode(gpio_t *obj, PinMode mode) {
|
||||
pin_mode(obj->pinName, mode);
|
||||
pin_mode(obj->pin, mode);
|
||||
}
|
||||
|
||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||
MBED_ASSERT(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
MBED_ASSERT(obj->pin != (PinName)NC);
|
||||
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
|
||||
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
|
||||
uint32_t pin_num = obj->pinName & 0xFF;
|
||||
uint32_t pin_num = obj->pin & 0xFF;
|
||||
|
||||
switch (direction) {
|
||||
case PIN_INPUT:
|
||||
|
|
|
@ -25,27 +25,31 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct {
|
||||
PinName pinName;
|
||||
PinName pin;
|
||||
} gpio_t;
|
||||
|
||||
static inline void gpio_write(gpio_t *obj, int value) {
|
||||
MBED_ASSERT(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pinName & 0xFF;
|
||||
MBED_ASSERT(obj->pin != (PinName)NC);
|
||||
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pin & 0xFF;
|
||||
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
|
||||
|
||||
GPIO_HAL_WritePinOutput(gpio_addrs[port], pin, value);
|
||||
}
|
||||
|
||||
static inline int gpio_read(gpio_t *obj) {
|
||||
MBED_ASSERT(obj->pinName != (PinName)NC);
|
||||
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pinName & 0xFF;
|
||||
MBED_ASSERT(obj->pin != (PinName)NC);
|
||||
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
|
||||
uint32_t pin = obj->pin & 0xFF;
|
||||
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
|
||||
|
||||
return (int)GPIO_HAL_ReadPinInput(gpio_addrs[port], pin);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -43,6 +43,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_mask_read) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -46,6 +46,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -45,6 +45,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -47,6 +47,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -63,6 +63,10 @@ static inline int gpio_read(gpio_t *obj) {
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -64,6 +64,10 @@ static inline int gpio_read(gpio_t *obj)
|
|||
return ((*obj->reg_in & obj->mask) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline int gpio_is_connected(const gpio_t *obj) {
|
||||
return obj->pin != (PinName)NC;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
namespace {
|
||||
BusOut bus_out(LED1, LED2, LED3, LED4);
|
||||
PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
notify_start();
|
||||
|
||||
bool result = false;
|
||||
|
||||
for (;;) {
|
||||
const int mask = bus_out.mask();
|
||||
int led_mask = 0x00;
|
||||
if (LED1 != NC) led_mask |= 0x01;
|
||||
if (LED2 != NC) led_mask |= 0x02;
|
||||
if (LED3 != NC) led_mask |= 0x04;
|
||||
if (LED4 != NC) led_mask |= 0x08;
|
||||
|
||||
printf("MBED: BusIn mask: 0x%X\r\n", mask);
|
||||
printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
|
||||
|
||||
// Let's check bus's connected pins mask
|
||||
if (mask != led_mask) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Checking if DigitalOut is correctly set as connected
|
||||
for (int i=0; i < 4; i++) {
|
||||
printf("MBED: BusOut.bit[%d] is %s\r\n",
|
||||
i,
|
||||
(led_pins[i] != NC && bus_out[i].is_connected())
|
||||
? "connected"
|
||||
: "not connected");
|
||||
}
|
||||
|
||||
for (int i=0; i < 4; i++) {
|
||||
if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write mask all LEDs
|
||||
bus_out.write(mask); // Set all LED's pins in high state
|
||||
if (bus_out.read() != mask) {
|
||||
break;
|
||||
}
|
||||
// Zero all LEDs and see if mask is correctly cleared on all bits
|
||||
bus_out.write(~mask);
|
||||
if (bus_out.read() != 0x00) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("MBED: Blinking LEDs: \r\n");
|
||||
|
||||
// Just a quick LED blinking...
|
||||
for (int i=0; i<4; i++) {
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 1;
|
||||
printf("%c", 'A' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
wait(0.2);
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 0;
|
||||
printf("%c", 'a' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
notify_completion(result);
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
#include "TestHarness.h"
|
||||
#include <utility>
|
||||
#include "mbed.h"
|
||||
|
||||
TEST_GROUP(BusOut_mask)
|
||||
{
|
||||
};
|
||||
|
||||
TEST(BusOut_mask, led_1_2_3)
|
||||
{
|
||||
BusOut bus_data(LED1, LED2, LED3);
|
||||
CHECK_EQUAL(0x07, bus_data.mask());
|
||||
}
|
||||
|
||||
TEST(BusOut_mask, led_nc_nc_nc_nc)
|
||||
{
|
||||
BusOut bus_data(NC, NC, NC, NC);
|
||||
CHECK_EQUAL(0x00, bus_data.mask());
|
||||
}
|
||||
|
||||
TEST(BusOut_mask, led_1_2_3_nc_nc)
|
||||
{
|
||||
BusOut bus_data(LED1, LED2, LED3, NC, NC);
|
||||
CHECK_EQUAL(0x07, bus_data.mask());
|
||||
}
|
||||
|
||||
TEST(BusOut_mask, led_1_nc_2_nc_nc_3)
|
||||
{
|
||||
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
|
||||
CHECK_EQUAL(0x25, bus_data.mask());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST_GROUP(BusOut_dummy)
|
||||
{
|
||||
};
|
||||
|
||||
TEST(BusOut_dummy, dummy)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
TEST_GROUP(BusOut_digitalout_write)
|
||||
{
|
||||
};
|
||||
|
||||
TEST(BusOut_digitalout_write, led_nc)
|
||||
{
|
||||
BusOut bus_data(NC);
|
||||
CHECK_EQUAL(false, bus_data[0].is_connected())
|
||||
}
|
||||
|
||||
|
||||
TEST(BusOut_digitalout_write, led_1_2_3)
|
||||
{
|
||||
BusOut bus_data(LED1, LED2, LED3);
|
||||
bus_data[0].write(1);
|
||||
bus_data[1].write(1);
|
||||
bus_data[2].write(1);
|
||||
CHECK(bus_data[0].read());
|
||||
CHECK(bus_data[1].read());
|
||||
CHECK(bus_data[2].read());
|
||||
}
|
||||
|
||||
TEST(BusOut_digitalout_write, led_1_2_3_nc_nc)
|
||||
{
|
||||
BusOut bus_data(LED1, LED2, LED3, NC, NC);
|
||||
bus_data[0].write(0);
|
||||
bus_data[1].write(0);
|
||||
bus_data[2].write(0);
|
||||
CHECK(bus_data[0].read() == 0);
|
||||
CHECK(bus_data[1].read() == 0);
|
||||
CHECK(bus_data[2].read() == 0);
|
||||
}
|
||||
|
||||
TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3)
|
||||
{
|
||||
BusOut bus_data(LED1, NC, LED2, NC, NC, LED3);
|
||||
bus_data[0].write(1);
|
||||
bus_data[2].write(0);
|
||||
bus_data[5].write(0);
|
||||
CHECK(bus_data[0].read());
|
||||
CHECK(bus_data[2].read() == 0);
|
||||
CHECK(bus_data[5].read() == 0);
|
||||
}
|
||||
#endif
|
|
@ -262,6 +262,14 @@ TESTS = [
|
|||
"duration": 15,
|
||||
},
|
||||
|
||||
{
|
||||
"id": "MBED_BUSOUT", "description": "BusOut",
|
||||
"source_dir": join(TEST_DIR, "mbed", "bus_out"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
|
||||
"automated": True,
|
||||
"duration": 15,
|
||||
},
|
||||
|
||||
# Size benchmarks
|
||||
{
|
||||
"id": "BENCHMARK_1", "description": "Size (c environment)",
|
||||
|
@ -527,7 +535,7 @@ TESTS = [
|
|||
"automated": True,
|
||||
"host_test": "wait_us_auto"
|
||||
},
|
||||
|
||||
|
||||
|
||||
# CMSIS RTOS tests
|
||||
{
|
||||
|
@ -899,6 +907,12 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY],
|
||||
"automated": False,
|
||||
},
|
||||
{
|
||||
"id": "UT_BUSIO", "description": "BusIn BusOut",
|
||||
"source_dir": join(TEST_DIR, "utest", "bus"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY],
|
||||
"automated": False,
|
||||
},
|
||||
|
||||
# Tests used for target information purposes
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue