mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Working PWM init
This commit is contained in:
@@ -19,17 +19,38 @@ uint16_t ADCReadings[ADC_NORM_SAMPLES]; // room for 32 lots of the pair of readi
|
||||
|
||||
// Functions
|
||||
|
||||
void setup_slow_PWM();
|
||||
void setup_timer_scheduler(void);
|
||||
void setup_pwm(void);
|
||||
void setup_adc(void);
|
||||
void hardware_init() {
|
||||
gpio_set_mode(OLED_RESET_Pin, GPIO_OUTPUT_MODE);
|
||||
gpio_set_mode(KEY_A_Pin, GPIO_INPUT_PD_MODE);
|
||||
gpio_set_mode(KEY_B_Pin, GPIO_INPUT_PD_MODE);
|
||||
setup_slow_PWM();
|
||||
setup_adc();
|
||||
I2C_ClockSet(I2C0_ID, 400000);
|
||||
}
|
||||
|
||||
setup_timer_scheduler();
|
||||
setup_adc();
|
||||
setup_pwm();
|
||||
I2C_ClockSet(I2C0_ID, 400000); // Sets clock to around 375kHz
|
||||
}
|
||||
void setup_pwm(void) {
|
||||
// Setup PWM we use for driving the tip
|
||||
PWM_CH_CFG_Type cfg = {
|
||||
PWM_Channel, // channel
|
||||
PWM_CLK_XCLK, // Clock
|
||||
PWM_STOP_GRACEFUL, // Stop mode
|
||||
PWM_POL_NORMAL, // Normal Polarity
|
||||
50, // Clock Div
|
||||
100, // Period
|
||||
0, // Thres 1 - start at beginng
|
||||
50, // Thres 2 - turn off at 50%
|
||||
0, // Interrupt pulse count
|
||||
};
|
||||
|
||||
BL_Err_Type err = PWM_Channel_Init(&cfg);
|
||||
uint32_t pwm_clk = peripheral_clock_get(PERIPHERAL_CLOCK_PWM);
|
||||
MSG((char *)"PWM Setup returns %d %d\r\n", err, pwm_clk);
|
||||
PWM_Channel_Enable(PWM_Channel);
|
||||
}
|
||||
void setup_adc(void) {
|
||||
MSG((char *)"Setting up ADC\r\n");
|
||||
//
|
||||
@@ -73,7 +94,7 @@ void setup_adc(void) {
|
||||
|
||||
struct device *timer0;
|
||||
|
||||
void setup_slow_PWM() {
|
||||
void setup_timer_scheduler() {
|
||||
|
||||
timer_register(TIMER0_INDEX, "timer0");
|
||||
|
||||
@@ -98,18 +119,11 @@ void setup_slow_PWM() {
|
||||
}
|
||||
|
||||
void setupFUSBIRQ() {
|
||||
return; // TODO
|
||||
|
||||
MSG((char *)"Setting up FUSB IRQ\r\n");
|
||||
gpio_set_mode(FUSB302_IRQ_Pin, GPIO_SYNC_FALLING_TRIGER_INT_MODE);
|
||||
MSG((char *)"Setting up FUSB IRQ1r\n");
|
||||
CPU_Interrupt_Disable(GPIO_INT0_IRQn);
|
||||
MSG((char *)"Setting up FUSB IRQ2\r\n");
|
||||
Interrupt_Handler_Register(GPIO_INT0_IRQn, GPIO_IRQHandler);
|
||||
MSG((char *)"Setting up FUSB IRQ3\r\n");
|
||||
CPU_Interrupt_Enable(GPIO_INT0_IRQn);
|
||||
|
||||
MSG((char *)"Setting up FUSB IRQ4\r\n");
|
||||
gpio_irq_enable(FUSB302_IRQ_Pin, ENABLE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user