/* os shim includes */ #include "os_types.h" #include "dbg_io.h" #include "iot_io.h" #include "gpio_mtx.h" #include "pwm.h" uint8_t pwm_gpio_sel(uint8_t port, uint8_t pwma, uint8_t pwmb) { gpio_mtx_enable(); volatile uint8_t pwma_func = 0; volatile uint8_t pwmb_func = 0; pwma_func = gpio_pin_func_get(pwma); pwmb_func = gpio_pin_func_get(pwmb); gpio_sig_info_t info = {0}; if (port == PWM_CHANNEL_0) { info.sig_type = 4; info.CFG[0].type = IO_TYPE_OUT; info.CFG[0].func = pwma_func; info.CFG[0].gpio = pwma; info.CFG[0].inid = 0xff; info.CFG[0].outid = 71; info.CFG[1].type = IO_TYPE_OUT; info.CFG[1].func = pwmb_func; info.CFG[1].gpio = pwmb; info.CFG[1].inid = 0xff; info.CFG[1].outid = 72; } else if (port == PWM_CHANNEL_1){ info.sig_type = 4; info.CFG[0].type = IO_TYPE_OUT; info.CFG[0].func = pwma_func; info.CFG[0].gpio = pwma; info.CFG[0].inid = 0xff; info.CFG[0].outid = 73; info.CFG[1].type = IO_TYPE_OUT; info.CFG[1].func = pwmb_func; info.CFG[1].gpio = pwmb; info.CFG[1].inid = 0xff; info.CFG[1].outid = 74; }else if (port == PWM_CHANNEL_2){ info.sig_type = 4; info.CFG[0].type = IO_TYPE_OUT; info.CFG[0].func = pwma_func; info.CFG[0].gpio = pwma; info.CFG[0].inid = 0xff; info.CFG[0].outid = 75; info.CFG[1].type = IO_TYPE_OUT; info.CFG[1].func = pwmb_func; info.CFG[1].gpio = pwmb; info.CFG[1].inid = 0xff; info.CFG[1].outid = 76; } gpio_module_pin_select(&info); gpio_module_sig_select(&info, GPIO_MTX_MODE_MATRIX); return 0; } void pwm_main(void) { volatile uint32_t delay =0; uint8_t duty = 0; dbg_uart_init(); pwm_gpio_sel( 0, 37, 38); pwm_init(); pwm_open(0, NULL); while(1) { for(duty = 0; duty <= 100; duty += 5) { pwm_set_duty(PWM_CHANNEL_0, duty * 100); iot_printf("PWM Duty: %d%%\r\n",duty); delay = 10000000; while(delay--); } for(duty = 100; duty > 0; duty -= 5) { pwm_set_duty(PWM_CHANNEL_1, duty * 100); iot_printf("PWM Duty: %d%%\r\n",duty); delay = 10000000; while(delay--); } } } #ifdef __GNUC__ int main(void) { pwm_main(); return 0; } #endif // __GCC__