mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_L152RE] Add analog out api
and add macros for GPIOs, change master timer for ticker.pull/150/head
parent
e3e5180256
commit
e577faef66
|
@ -41,6 +41,10 @@ typedef enum {
|
|||
ADC_2 = (int)ADC_BASE
|
||||
} ADCName;
|
||||
|
||||
typedef enum {
|
||||
DAC_1 = (int)DAC_BASE
|
||||
} DACName;
|
||||
|
||||
typedef enum {
|
||||
UART_1 = (int)USART1_BASE,
|
||||
UART_2 = (int)USART2_BASE
|
||||
|
|
|
@ -46,15 +46,17 @@ extern "C" {
|
|||
#define STM_PIN_PUPD(X) (((X)>>4) & 0x3)
|
||||
#define STM_PIN_AFNUM(X) (((X)>>8) & 0xF)
|
||||
|
||||
// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
|
||||
// Low nibble = pin number
|
||||
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
|
||||
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
|
||||
|
||||
typedef enum {
|
||||
PIN_INPUT,
|
||||
PIN_OUTPUT
|
||||
} PinDirection;
|
||||
|
||||
typedef enum {
|
||||
|
||||
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
|
||||
// low nibble = pin number
|
||||
PA_0 = 0x00,
|
||||
PA_1 = 0x01,
|
||||
PA_2 = 0x02,
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
#define DEVICE_INTERRUPTIN 0
|
||||
|
||||
#define DEVICE_ANALOGIN 0
|
||||
#define DEVICE_ANALOGOUT 0
|
||||
#define DEVICE_ANALOGIN 1
|
||||
#define DEVICE_ANALOGOUT 1
|
||||
|
||||
#define DEVICE_SERIAL 1
|
||||
|
||||
|
|
|
@ -44,8 +44,7 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
|
|||
|
||||
if (pin == NC) return;
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
uint32_t port_index = (pin_number >> 4);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
|
||||
// Get GPIO structure base address
|
||||
switch (port_index) {
|
||||
|
|
|
@ -58,6 +58,11 @@ struct analogin_s {
|
|||
PinName pin;
|
||||
};
|
||||
|
||||
struct dac_s {
|
||||
DACName dac;
|
||||
PinName channel;
|
||||
};
|
||||
|
||||
struct serial_s {
|
||||
UARTName uart;
|
||||
int index; // Used by irq
|
||||
|
|
|
@ -45,10 +45,9 @@ void pin_function(PinName pin, int data) {
|
|||
uint32_t pupd = STM_PIN_PUPD(data);
|
||||
uint32_t afnum = STM_PIN_AFNUM(data);
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
uint32_t pin_index = (pin_number & 0xF);
|
||||
uint32_t port_index = (pin_number >> 4);
|
||||
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Get GPIO structure base address and enable clock
|
||||
switch (port_index) {
|
||||
case PortA:
|
||||
|
@ -108,9 +107,8 @@ void pin_mode(PinName pin, PinMode mode) {
|
|||
|
||||
if (pin == NC) return;
|
||||
|
||||
uint32_t pin_number = (uint32_t)pin;
|
||||
uint32_t pin_index = (pin_number & 0xF);
|
||||
uint32_t port_index = (pin_number >> 4);
|
||||
uint32_t port_index = STM_PORT(pin);
|
||||
uint32_t pin_index = STM_PIN(pin);
|
||||
|
||||
// Get GPIO structure base address and enable clock
|
||||
switch (port_index) {
|
||||
|
|
|
@ -32,15 +32,15 @@
|
|||
// Timers selection:
|
||||
// The Master timer clocks the Slave timer
|
||||
|
||||
#define TIM_MST TIM3
|
||||
#define TIM_MST_IRQ TIM3_IRQn
|
||||
#define TIM_MST_RCC RCC_APB1Periph_TIM3
|
||||
#define TIM_MST TIM9
|
||||
#define TIM_MST_IRQ TIM9_IRQn
|
||||
#define TIM_MST_RCC RCC_APB2Periph_TIM9
|
||||
|
||||
#define TIM_SLV TIM4
|
||||
#define TIM_SLV_IRQ TIM4_IRQn
|
||||
#define TIM_SLV_RCC RCC_APB1Periph_TIM4
|
||||
|
||||
#define MST_SLV_ITR TIM_TS_ITR2
|
||||
#define MST_SLV_ITR TIM_TS_ITR3
|
||||
|
||||
int us_ticker_inited = 0;
|
||||
|
||||
|
@ -53,7 +53,7 @@ void us_ticker_init(void) {
|
|||
us_ticker_inited = 1;
|
||||
|
||||
// Enable Timers clock
|
||||
RCC_APB1PeriphClockCmd(TIM_MST_RCC, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(TIM_MST_RCC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(TIM_SLV_RCC, ENABLE);
|
||||
|
||||
// Master and Slave timers time base configuration
|
||||
|
|
Loading…
Reference in New Issue