Added PWM

This commit is contained in:
Tom-on64 2026-04-24 16:57:53 +02:00
parent e375586804
commit afaa87daec
2 changed files with 25 additions and 0 deletions

21
pwm.c Normal file
View File

@ -0,0 +1,21 @@
#include <hardware/pwm.h>
#include <pico/types.h>
#include "const.h"
#include "pwm.h"
void pwm_isr(void) {
static uint slice = -1, chan = -1;
if (slice == -1) slice = pwm_gpio_to_slice_num(AUDIO_OUT);
if (chan == -1) chan = pwm_gpio_to_channel(AUDIO_OUT);
pwm_clear_irq(slice);
// TODO:
float sample = 0.0f;
uint16_t level = (uint16_t)((sample + 1.0f) * 0.5f * 3400.0f);
pwm_set_chan_level(slice, chan, level);
}

4
pwm.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
void pwm_isr(void);