Merge branch 'tingleby-pin'
This commit is contained in:
21
api/maa.h
21
api/maa.h
@@ -61,6 +61,19 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
typedef unsigned int maa_boolean_t;
|
typedef unsigned int maa_boolean_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing different possible modes for a pin.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
MAA_PIN_VALID = 0, /**< Pin Valid */
|
||||||
|
MAA_PIN_GPIO = 1, /**< General Purpose IO */
|
||||||
|
MAA_PIN_PWM = 2, /**< Pulse Width Modulation */
|
||||||
|
MAA_PIN_FAST_GPIO = 3, /**< Faster GPIO */
|
||||||
|
MAA_PIN_SPI = 4, /**< SPI */
|
||||||
|
MAA_PIN_I2C = 5, /**< I2C */
|
||||||
|
MAA_PIN_AIO = 6 /**< Analog in */
|
||||||
|
} maa_pinmodes_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bitfield representing the capabilities of a pin.
|
* A bitfield representing the capabilities of a pin.
|
||||||
*/
|
*/
|
||||||
@@ -208,6 +221,14 @@ const char* maa_get_version();
|
|||||||
*/
|
*/
|
||||||
void maa_result_print(maa_result_t result);
|
void maa_result_print(maa_result_t result);
|
||||||
|
|
||||||
|
/** Checks if a pin is able to use the passed in mode.
|
||||||
|
*
|
||||||
|
* @param pin Physical Pin to be checked.
|
||||||
|
* @param mode the mode to be tested.
|
||||||
|
* @return boolean if the mode is supported, 0=false.
|
||||||
|
*/
|
||||||
|
maa_boolean_t maa_pin_mode_test(int pin, maa_pinmodes_t mode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
70
src/maa.c
70
src/maa.c
@@ -142,20 +142,20 @@ maa_check_pwm(int pin)
|
|||||||
if (plat->pins[pin].capabilites.pwm != 1)
|
if (plat->pins[pin].capabilites.pwm != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/** quirk in rev d, this messes with pwm on that pin
|
if (plat->pins[pin].capabilites.gpio == 1) {
|
||||||
* if (plat->pins[pin].capabilites.gpio == 1) {
|
maa_gpio_context* mux_i;
|
||||||
* maa_gpio_context* mux_i;
|
mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
||||||
* mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
|
if (mux_i == NULL)
|
||||||
* if (mux_i == NULL)
|
return NULL;
|
||||||
* return NULL;
|
if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
||||||
* if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
|
return NULL;
|
||||||
* return NULL;
|
// Current REV D quirk. //TODO GEN 2
|
||||||
* if (maa_gpio_write(mux_i, 0) != MAA_SUCCESS)
|
if (maa_gpio_write(mux_i, 1) != MAA_SUCCESS)
|
||||||
* return NULL;
|
return NULL;
|
||||||
* if (maa_gpio_close(mux_i) != MAA_SUCCESS)
|
if (maa_gpio_close(mux_i) != MAA_SUCCESS)
|
||||||
* return NULL;
|
return NULL;
|
||||||
* }
|
}
|
||||||
*/
|
|
||||||
if (plat->pins[pin].pwm.mux_total > 0)
|
if (plat->pins[pin].pwm.mux_total > 0)
|
||||||
if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
|
if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -216,3 +216,45 @@ maa_result_print(maa_result_t result)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maa_boolean_t
|
||||||
|
maa_pin_mode_test(int pin, maa_pinmodes_t mode)
|
||||||
|
{
|
||||||
|
if (pin > plat->phy_pin_count || pin < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
switch(mode) {
|
||||||
|
case MAA_PIN_VALID:
|
||||||
|
if (plat->pins[pin].capabilites.valid == 1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_GPIO:
|
||||||
|
if (plat->pins[pin].capabilites.gpio ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_PWM:
|
||||||
|
if (plat->pins[pin].capabilites.pwm ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_FAST_GPIO:
|
||||||
|
if (plat->pins[pin].capabilites.fast_gpio ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_SPI:
|
||||||
|
if (plat->pins[pin].capabilites.spi ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_I2C:
|
||||||
|
if (plat->pins[pin].capabilites.i2c ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
case MAA_PIN_AIO:
|
||||||
|
if (pin < plat->aio_count)
|
||||||
|
pin = pin + plat->gpio_count;
|
||||||
|
if (plat->pins[pin].capabilites.aio ==1)
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user