Commit becbc87f authored by Dave Hylands's avatar Dave Hylands
Browse files

Add Timer support (PWM, OC, IC) for stmhal and teensy

parent 2842945e
......@@ -413,7 +413,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
STATIC mp_obj_t pin_obj_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
return pin_obj_init_helper(args[0], n_args - 1, args + 1, kw_args);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
MP_DEFINE_CONST_FUN_OBJ_KW(pin_init_obj, 1, pin_obj_init);
/// \method value([value])
/// Get or set the digital logic level of the pin:
......
......@@ -82,12 +82,14 @@ extern const mp_obj_type_t pin_cpu_pins_obj_type;
extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
extern const mp_obj_dict_t pin_board_pins_locals_dict;
MP_DECLARE_CONST_FUN_OBJ(pin_init_obj);
void pin_init0(void);
uint32_t pin_get_mode(const pin_obj_t *pin);
uint32_t pin_get_pull(const pin_obj_t *pin);
uint32_t pin_get_af(const pin_obj_t *pin);
const pin_obj_t *pin_find(mp_obj_t user_obj);
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit, uint8_t pin_type);
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit);
const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx);
const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name);
......@@ -64,17 +64,15 @@ const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t na
return NULL;
}
/* unused
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit, uint8_t type) {
const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit) {
const pin_af_obj_t *af = pin->af;
for (mp_uint_t i = 0; i < pin->num_af; i++, af++) {
if (af->fn == fn && af->unit == unit && af->type == type) {
if (af->fn == fn && af->unit == unit) {
return af;
}
}
return NULL;
}
*/
const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx) {
const pin_af_obj_t *af = pin->af;
......
......@@ -144,6 +144,9 @@ Q(recv)
// for Timer class
Q(Timer)
Q(init)
Q(deinit)
Q(channel)
Q(counter)
Q(prescaler)
Q(period)
......@@ -151,6 +154,30 @@ Q(callback)
Q(freq)
Q(mode)
Q(div)
Q(UP)
Q(DOWN)
Q(CENTER)
Q(IC)
Q(PWM)
Q(PWM_INVERTED)
Q(OC_TIMING)
Q(OC_ACTIVE)
Q(OC_INACTIVE)
Q(OC_TOGGLE)
Q(OC_FORCED_ACTIVE)
Q(OC_FORCED_INACTIVE)
Q(HIGH)
Q(LOW)
Q(RISING)
Q(FALLING)
Q(BOTH)
// for TimerChannel class
Q(TimerChannel)
Q(pulse_width)
Q(compare)
Q(capture)
Q(polarity)
// for ExtInt class
Q(ExtInt)
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ extern TIM_HandleTypeDef TIM5_Handle;
extern TIM_HandleTypeDef TIM6_Handle;
extern const mp_obj_type_t pyb_timer_type;
extern const mp_obj_type_t pyb_timer_channel_type;
void timer_init0(void);
void timer_tim3_init(void);
......
......@@ -42,8 +42,11 @@ CFLAGS += -Og -ggdb
else
CFLAGS += -Os #-DNDEBUG
endif
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -Wl,--gc-sections
SRC_C = \
hal_ftm.c \
hal_gpio.c \
help.c \
import.c \
......@@ -54,7 +57,9 @@ SRC_C = \
memzip.c \
modpyb.c \
pin_defs_teensy.c \
reg.c \
teensy_hal.c \
timer.c \
uart.c \
usb.c \
......@@ -141,6 +146,7 @@ GEN_PINS_SRC = $(BUILD)/pins_gen.c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
# Making OBJ use an order-only depenedency on the generated pins.h file
# has the side effect of making the pins.h file before we actually compile
......@@ -153,7 +159,7 @@ $(OBJ): | $(HEADER_BUILD)/pins.h
# both pins_$(BOARD).c and pins.h
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: teensy_%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
$(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c
$(call compile_c)
......
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdint.h>
#include <mk20dx128.h>
#include "teensy_hal.h"
void HAL_FTM_Base_Init(FTM_HandleTypeDef *hftm) {
/* Check the parameters */
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
assert_param(IS_FTM_PRESCALERSHIFT(hftm->Init.PrescalerShift));
assert_param(IS_FTM_COUNTERMODE(hftm->Init.CounterMode));
assert_param(IS_FTM_PERIOD(hftm->Init.Period));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->MODE = FTM_MODE_WPDIS;
FTMx->SC = 0;
FTMx->MOD = hftm->Init.Period;
uint32_t sc = FTM_SC_PS(hftm->Init.PrescalerShift);
if (hftm->Init.CounterMode == FTM_COUNTERMODE_CENTER) {
sc |= FTM_SC_CPWMS;
}
FTMx->SC = sc;
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_Base_Start(FTM_HandleTypeDef *hftm) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->CNT = 0;
FTMx->SC &= ~FTM_SC_CLKS(3);
FTMx->SC |= FTM_SC_CLKS(1);
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_Base_Start_IT(FTM_HandleTypeDef *hftm) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->CNT = 0;
FTMx->SC |= FTM_SC_CLKS(1) | FTM_SC_TOIE;
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_Base_DeInit(FTM_HandleTypeDef *hftm) {
assert_param(IS_FTM_INSTANCE(hftm->Instance));
hftm->State = HAL_FTM_STATE_BUSY;
__HAL_FTM_DISABLE_TOF_IT(hftm);
hftm->State = HAL_FTM_STATE_RESET;
}
void HAL_FTM_OC_Init(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_Init(hftm);
}
void HAL_FTM_OC_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_OC_InitTypeDef* sConfig, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
assert_param(IS_FTM_CHANNEL(channel));
assert_param(IS_FTM_OC_MODE(sConfig->OCMode));
assert_param(IS_FTM_OC_PULSE(sConfig->Pulse));
assert_param(IS_FTM_OC_POLARITY(sConfig->OCPolarity));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->channel[channel].CSC = sConfig->OCMode;
FTMx->channel[channel].CV = sConfig->Pulse;
if (sConfig->OCPolarity & 1) {
FTMx->POL |= (1 << channel);
} else {
FTMx->POL &= ~(1 << channel);
}
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_OC_Start(FTM_HandleTypeDef *hftm, uint32_t channel) {
// Nothing else to do
}
void HAL_FTM_OC_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
FTMx->channel[channel].CSC |= FTM_CSC_CHIE;
}
void HAL_FTM_OC_DeInit(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_DeInit(hftm);
}
void HAL_FTM_PWM_Init(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_Init(hftm);
}
void HAL_FTM_PWM_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_OC_InitTypeDef* sConfig, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
assert_param(IS_FTM_CHANNEL(channel));
assert_param(IS_FTM_PWM_MODE(sConfig->OCMode));
assert_param(IS_FTM_OC_PULSE(sConfig->Pulse));
assert_param(IS_FTM_OC_POLARITY(sConfig->OCPolarity));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->channel[channel].CSC = sConfig->OCMode;
FTMx->channel[channel].CV = sConfig->Pulse;
if (sConfig->OCPolarity & 1) {
FTMx->POL |= (1 << channel);
} else {
FTMx->POL &= ~(1 << channel);
}
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_PWM_Start(FTM_HandleTypeDef *hftm, uint32_t channel) {
// Nothing else to do
}
void HAL_FTM_PWM_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
FTMx->channel[channel].CSC |= FTM_CSC_CHIE;
}
void HAL_FTM_PWM_DeInit(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_DeInit(hftm);
}
void HAL_FTM_IC_Init(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_Init(hftm);
}
void HAL_FTM_IC_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_IC_InitTypeDef* sConfig, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
assert_param(IS_FTM_CHANNEL(channel));
assert_param(IS_FTM_IC_POLARITY(sConfig->ICPolarity));
hftm->State = HAL_FTM_STATE_BUSY;
FTMx->channel[channel].CSC = sConfig->ICPolarity;
hftm->State = HAL_FTM_STATE_READY;
}
void HAL_FTM_IC_Start(FTM_HandleTypeDef *hftm, uint32_t channel) {
//FTM_TypeDef *FTMx = hftm->Instance;
//assert_param(IS_FTM_INSTANCE(FTMx));
// Nothing else to do
}
void HAL_FTM_IC_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel) {
FTM_TypeDef *FTMx = hftm->Instance;
assert_param(IS_FTM_INSTANCE(FTMx));
FTMx->channel[channel].CSC |= FTM_CSC_CHIE;
}
void HAL_FTM_IC_DeInit(FTM_HandleTypeDef *hftm) {
HAL_FTM_Base_DeInit(hftm);
}
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define FTM0 ((FTM_TypeDef *)&FTM0_SC)
#define FTM1 ((FTM_TypeDef *)&FTM1_SC)
#define FTM2 ((FTM_TypeDef *)&FTM2_SC)
typedef struct {
volatile uint32_t CSC; // Channel x Status And Control
volatile uint32_t CV; // Channel x Value
} FTM_ChannelTypeDef;
typedef struct {
volatile uint32_t SC; // Status And Control
volatile uint32_t CNT; // Counter
volatile uint32_t MOD; // Modulo
FTM_ChannelTypeDef channel[8];
volatile uint32_t CNTIN; // Counter Initial Value
volatile uint32_t STATUS; // Capture And Compare Status
volatile uint32_t MODE; // Features Mode Selection
volatile uint32_t SYNC; // Synchronization
volatile uint32_t OUTINIT; // Initial State For Channels Output
volatile uint32_t OUTMASK; // Output Mask
volatile uint32_t COMBINE; // Function For Linked Channels
volatile uint32_t DEADTIME; // Deadtime Insertion Control
volatile uint32_t EXTTRIG; // FTM External Trigger
volatile uint32_t POL; // Channels Polarity
volatile uint32_t FMS; // Fault Mode Status
volatile uint32_t FILTER; // Input Capture Filter Control
volatile uint32_t FLTCTRL; // Fault Control
volatile uint32_t QDCTRL; // Quadrature Decoder Control And Status
volatile uint32_t CONF; // Configuration
volatile uint32_t FLTPOL; // FTM Fault Input Polarity
volatile uint32_t SYNCONF; // Synchronization Configuration
volatile uint32_t INVCTRL; // FTM Inverting Control
volatile uint32_t SWOCTRL; // FTM Software Output Control
volatile uint32_t PWMLOAD; // FTM PWM Load
} FTM_TypeDef;
typedef struct {
uint32_t PrescalerShift; // Sets the prescaler to 1 << PrescalerShift
uint32_t CounterMode; // One of FTM_COUNTERMODE_xxx
uint32_t Period; // Specifies the Period for determining timer overflow
} FTM_Base_InitTypeDef;
typedef struct {
uint32_t OCMode; // One of FTM_OCMODE_xxx
uint32_t Pulse; // Specifies initial pulse width (0-0xffff)
uint32_t OCPolarity; // One of FTM_OCPOLRITY_xxx
} FTM_OC_InitTypeDef;
typedef struct {
uint32_t ICPolarity; // Specifies Rising/Falling/Both
} FTM_IC_InitTypeDef;
#define IS_FTM_INSTANCE(INSTANCE) (((INSTANCE) == FTM0) || \
((INSTANCE) == FTM1) || \
((INSTANCE) == FTM2))
#define IS_FTM_PRESCALERSHIFT(PRESCALERSHIFT) (((PRESCALERSHIFT) & ~7) == 0)
#define FTM_COUNTERMODE_UP (0)
#define FTM_COUNTERMODE_CENTER (FTM_SC_CPWMS)
#define IS_FTM_COUNTERMODE(MODE) (((MODE) == FTM_COUNTERMODE_UP) ||\
((MODE) == FTM_COUNTERMODE_CENTER))
#define IS_FTM_PERIOD(PERIOD) (((PERIOD) & 0xFFFF0000) == 0)
#define FTM_CSC_CHF 0x80
#define FTM_CSC_CHIE 0x40
#define FTM_CSC_MSB 0x20
#define FTM_CSC_MSA 0x10
#define FTM_CSC_ELSB 0x08
#define FTM_CSC_ELSA 0x04
#define FTM_CSC_DMA 0x01
#define FTM_OCMODE_TIMING (0)
#define FTM_OCMODE_ACTIVE (FTM_CSC_MSA | FTM_CSC_ELSB | FTM_CSC_ELSA)
#define FTM_OCMODE_INACTIVE (FTM_CSC_MSA | FTM_CSC_ELSB)
#define FTM_OCMODE_TOGGLE (FTM_CSC_MSA | FTM_CSC_ELSA)
#define FTM_OCMODE_PWM1 (FTM_CSC_MSB | FTM_CSC_ELSB)
#define FTM_OCMODE_PWM2 (FTM_CSC_MSB | FTM_CSC_ELSA)
#define IS_FTM_OC_MODE(mode) ((mode) == FTM_OCMODE_TIMING || \
(mode) == FTM_OCMODE_ACTIVE || \
(mode) == FTM_OCMODE_INACTIVE || \
(mode) == FTM_OCMODE_TOGGLE )
#define IS_FTM_PWM_MODE(mode) ((mode) == FTM_OCMODE_PWM1 || \
(mode) == FTM_OCMODE_PWM2)
#define IS_FTM_CHANNEL(channel) (((channel) & ~7) == 0)
#define IS_FTM_PULSE(pulse) (((pulse) & ~0xffff) == 0)
#define FTM_OCPOLARITY_HIGH (0)
#define FTM_OCPOLARITY_LOW (1)
#define IS_FTM_OC_POLARITY(polarity) ((polarity) == FTM_OCPOLARITY_HIGH || \
(polarity) == FTM_OCPOLARITY_LOW)
#define FTM_ICPOLARITY_RISING (FTM_CSC_ELSA)
#define FTM_ICPOLARITY_FALLING (FTM_CSC_ELSB)
#define FTM_ICPOLARITY_BOTH (FTM_CSC_ELSA | FTM_CSC_ELSB)
#define IS_FTM_IC_POLARITY(polarity) ((polarity) == FTM_ICPOLARITY_RISING || \
(polarity) == FTM_ICPOLARITY_FALLING || \
(polarity) == FTM_ICPOLARITY_BOTH)
typedef enum {
HAL_FTM_STATE_RESET = 0x00,
HAL_FTM_STATE_READY = 0x01,
HAL_FTM_STATE_BUSY = 0x02,
} HAL_FTM_State;
typedef struct {
FTM_TypeDef *Instance;
FTM_Base_InitTypeDef Init;
HAL_FTM_State State;
} FTM_HandleTypeDef;
#define __HAL_FTM_GET_TOF_FLAG(HANDLE) (((HANDLE)->Instance->SC & FTM_SC_TOF) != 0)
#define __HAL_FTM_CLEAR_TOF_FLAG(HANDLE) ((HANDLE)->Instance->SC &= ~FTM_SC_TOF)
#define __HAL_FTM_GET_TOF_IT(HANDLE) (((HANDLE)->Instance->SC & FTM_SC_TOIE) != 0)
#define __HAL_FTM_ENABLE_TOF_IT(HANDLE) ((HANDLE)->Instance->SC |= FTM_SC_TOIE)
#define __HAL_FTM_DISABLE_TOF_IT(HANDLE) ((HANDLE)->Instance->SC &= ~FTM_SC_TOIE)
#define __HAL_FTM_GET_CH_FLAG(HANDLE, CH) (((HANDLE)->Instance->channel[CH].CSC & FTM_CSC_CHF) != 0)
#define __HAL_FTM_CLEAR_CH_FLAG(HANDLE, CH) ((HANDLE)->Instance->channel[CH].CSC &= ~FTM_CSC_CHF)
#define __HAL_FTM_GET_CH_IT(HANDLE, CH) (((HANDLE)->Instance->channel[CH].CSC & FTM_CSC_CHIE) != 0)
#define __HAL_FTM_ENABLE_CH_IT(HANDLE, CH) ((HANDLE)->Instance->channel[CH].CSC |= FTM_CSC_CHIE)
#define __HAL_FTM_DISABLE_CH_IT(HANDLE, CH) ((HANDLE)->Instance->channel[CH].CSC &= ~FTM_CSC_CHIE)
void HAL_FTM_Base_Init(FTM_HandleTypeDef *hftm);
void HAL_FTM_Base_Start(FTM_HandleTypeDef *hftm);
void HAL_FTM_Base_Start_IT(FTM_HandleTypeDef *hftm);
void HAL_FTM_Base_DeInit(FTM_HandleTypeDef *hftm);
void HAL_FTM_OC_Init(FTM_HandleTypeDef *hftm);
void HAL_FTM_OC_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_OC_InitTypeDef* sConfig, uint32_t channel);
void HAL_FTM_OC_Start(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_OC_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_OC_DeInit(FTM_HandleTypeDef *hftm);
void HAL_FTM_PWM_Init(FTM_HandleTypeDef *hftm);
void HAL_FTM_PWM_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_OC_InitTypeDef* sConfig, uint32_t channel);
void HAL_FTM_PWM_Start(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_PWM_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_PWM_DeInit(FTM_HandleTypeDef *hftm);
void HAL_FTM_IC_Init(FTM_HandleTypeDef *hftm);
void HAL_FTM_IC_ConfigChannel(FTM_HandleTypeDef *hftm, FTM_IC_InitTypeDef* sConfig, uint32_t channel);
void HAL_FTM_IC_Start(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_IC_Start_IT(FTM_HandleTypeDef *hftm, uint32_t channel);
void HAL_FTM_IC_DeInit(FTM_HandleTypeDef *hftm);
......@@ -17,7 +17,6 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
if ((GPIO_Init->Pin & bitmask) == 0) {
continue;
}
volatile uint32_t *port_pcr = GPIO_PIN_TO_PORT_PCR(GPIOx, position);
/*--------------------- GPIO Mode Configuration ------------------------*/
......@@ -50,6 +49,8 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
/* Check the Speed parameter */
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
*port_pcr |= PORT_PCR_DSE;
/* Configure the IO Speed */
if (GPIO_Init->Speed > GPIO_SPEED_MEDIUM) {
*port_pcr &= ~PORT_PCR_SRE;
......@@ -59,10 +60,12 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
/* Configure the IO Output Type */
if (GPIO_Init->Mode & GPIO_OUTPUT_TYPE) {
*port_pcr |= PORT_PCR_ODE;
*port_pcr |= PORT_PCR_ODE; // OD
} else {
*port_pcr &= ~PORT_PCR_ODE;
*port_pcr &= ~PORT_PCR_ODE; // PP
}
} else {
*port_pcr &= ~PORT_PCR_DSE;
}
/* Activate the Pull-up or Pull down resistor for the current IO */
......
......@@ -8,7 +8,7 @@ import sys
import csv
SUPPORTED_FN = {
'FTM' : ['CH0', 'CH1', 'CH2', 'CH3',
'FTM' : ['CH0', 'CH1', 'CH2', 'CH3', 'CH4', 'CH5', 'CH6', 'CH7',
'QD_PHA', 'QD_PHB'],
'I2C' : ['SDA', 'SCL'],
'UART' : ['RX', 'TX', 'CTS', 'RTS'],
......@@ -313,6 +313,17 @@ class Pins(object):
print(' { %-*s %s },' % (mux_name_width + 26, key, val),
file=af_const_file)
def print_af_py(self, af_py_filename):
with open(af_py_filename, 'wt') as af_py_file:
print('PINS_AF = (', file=af_py_file);
for named_pin in self.board_pins:
print(" ('%s', " % named_pin.name(), end='', file=af_py_file)
for af in named_pin.pin().alt_fn:
if af.is_supported():
print("(%d, '%s'), " % (af.idx, af.af_str), end='', file=af_py_file)
print('),', file=af_py_file)
print(')', file=af_py_file)
def main():
parser = argparse.ArgumentParser(
......@@ -324,13 +335,19 @@ def main():
"-a", "--af",
dest="af_filename",
help="Specifies the alternate function file for the chip",
default="stm32f4xx-af.csv"
default="mk20dx256_af.csv"
)
parser.add_argument(
"--af-const",
dest="af_const_filename",
help="Specifies header file for alternate function constants.",
default="build/pins-af-const.h"
default="build/pins_af_const.h"
)
parser.add_argument(
"--af-py",
dest="af_py_filename",
help="Specifies the filename for the python alternate function mappings.",
default="build/pins_af.py"
)
parser.add_argument(
"-b", "--board",
......@@ -341,13 +358,13 @@ def main():
"-p", "--prefix",
dest="prefix_filename",
help="Specifies beginning portion of generated pins file",
default="stm32f4xx-prefix.c"
default="mk20dx256_prefix.c"
)
parser.add_argument(
"-q", "--qstr",
dest="qstr_filename",
help="Specifies name of generated qstr header file",
default="build/pins-qstr.h"
default="build/pins_qstr.h"
)
parser.add_argument(
"-r", "--hdr",
......@@ -381,6 +398,7 @@ def main():
pins.print_header(args.hdr_filename)
pins.print_qstr(args.qstr_filename)
pins.print_af_hdr(args.af_const_filename)
pins.print_af_py(args.af_py_filename)