add other audio
This commit is contained in:
parent
17c82e5a6c
commit
3ea7aac1f4
5 changed files with 21 additions and 32 deletions
Binary file not shown.
BIN
ch32v-insert-coin/audio/coin2.raw
Normal file
BIN
ch32v-insert-coin/audio/coin2.raw
Normal file
Binary file not shown.
|
|
@ -1,9 +1,8 @@
|
||||||
use ch32_hal::timer::GeneralInstance16bit;
|
|
||||||
use ch32_hal::timer::simple_pwm::SimplePwm;
|
use ch32_hal::timer::simple_pwm::SimplePwm;
|
||||||
use ch32_hal::timer::Channel;
|
use ch32_hal::timer::Channel;
|
||||||
|
use ch32_hal::timer::GeneralInstance16bit;
|
||||||
|
|
||||||
use crate::insert_coin::services::{DacService, LedService, TickService, TickServiceData, Service};
|
use crate::insert_coin::services::{DacService, LedService, Service, TickService, TickServiceData};
|
||||||
|
|
||||||
|
|
||||||
// static mut led0_index: usize = 0;
|
// static mut led0_index: usize = 0;
|
||||||
// static LED0: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
// static LED0: [u8; 8] = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
||||||
|
|
@ -43,17 +42,12 @@ impl<'d, T: GeneralInstance16bit> SimplePwmCore<'d, T> {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct CoreConfig {
|
pub struct CoreConfig {
|
||||||
pub tick_rate_hz: usize,
|
pub tick_rate_hz: usize,
|
||||||
}
|
}
|
||||||
impl CoreConfig {
|
impl CoreConfig {
|
||||||
pub fn new(tick_rate_hz: usize) -> Self {
|
pub fn new(tick_rate_hz: usize) -> Self {
|
||||||
Self {
|
Self { tick_rate_hz }
|
||||||
tick_rate_hz,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,25 +64,20 @@ pub struct InsertCoin<'a, T: GeneralInstance16bit> {
|
||||||
pub led0: LedService,
|
pub led0: LedService,
|
||||||
pub led1: LedService,
|
pub led1: LedService,
|
||||||
// led2: LedService,
|
// led2: LedService,
|
||||||
|
|
||||||
pub dac: DacService<'a>,
|
pub dac: DacService<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: GeneralInstance16bit> InsertCoin<'a, T> {
|
impl<'a, T: GeneralInstance16bit> InsertCoin<'a, T> {
|
||||||
|
|
||||||
pub fn new(config: CoreConfig, pwm_core: SimplePwmCore<'a, T>) -> Self {
|
pub fn new(config: CoreConfig, pwm_core: SimplePwmCore<'a, T>) -> Self {
|
||||||
|
|
||||||
|
|
||||||
// LED0 servicer setup
|
// LED0 servicer setup
|
||||||
let led0 = LedService::new(ch32_hal::timer::Channel::Ch3);
|
let led0 = LedService::new(ch32_hal::timer::Channel::Ch3);
|
||||||
|
|
||||||
// LED1 servicer setup
|
// LED1 servicer setup
|
||||||
let led1 = LedService::new(ch32_hal::timer::Channel::Ch1);
|
let led1 = LedService::new(ch32_hal::timer::Channel::Ch1);
|
||||||
|
|
||||||
|
|
||||||
// DAC servicer setup
|
// DAC servicer setup
|
||||||
let dac_sample_rate_hz = 16000;
|
let dac_sample_rate_hz = 4000;
|
||||||
let dac_tick_per_service = config.tick_rate_hz/(dac_sample_rate_hz);
|
let dac_tick_per_service = config.tick_rate_hz / (dac_sample_rate_hz);
|
||||||
let dac_service_data = TickServiceData::new(dac_tick_per_service);
|
let dac_service_data = TickServiceData::new(dac_tick_per_service);
|
||||||
let dac = DacService::new(ch32_hal::timer::Channel::Ch4, dac_service_data);
|
let dac = DacService::new(ch32_hal::timer::Channel::Ch4, dac_service_data);
|
||||||
|
|
||||||
|
|
@ -105,28 +94,28 @@ impl<'a, T: GeneralInstance16bit> InsertCoin<'a, T> {
|
||||||
|
|
||||||
/// takes self reference and runs
|
/// takes self reference and runs
|
||||||
pub fn service(&mut self) {
|
pub fn service(&mut self) {
|
||||||
|
|
||||||
if self.is_active() {
|
if self.is_active() {
|
||||||
self.dac.tick();
|
self.dac.tick();
|
||||||
|
|
||||||
|
|
||||||
if self.led0.need_service() {
|
if self.led0.need_service() {
|
||||||
self.pwm_core.write_amplitude(self.led0.channel, self.led0.amplitude);
|
self.pwm_core
|
||||||
|
.write_amplitude(self.led0.channel, self.led0.amplitude);
|
||||||
self.led0.service();
|
self.led0.service();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.led1.need_service() {
|
if self.led1.need_service() {
|
||||||
self.pwm_core.write_amplitude(self.led1.channel, self.led1.amplitude);
|
self.pwm_core
|
||||||
|
.write_amplitude(self.led1.channel, self.led1.amplitude);
|
||||||
self.led1.service();
|
self.led1.service();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.dac.need_service() {
|
if self.dac.need_service() {
|
||||||
self.dac.service();
|
self.dac.service();
|
||||||
// TODO: adpcm-pwm-dac:e4c811653781e69e40b63fd27a8c1e20
|
// TODO: adpcm-pwm-dac:e4c811653781e69e40b63fd27a8c1e20
|
||||||
self.pwm_core.write_amplitude(self.dac.channel, self.dac.get_amplitude() as u8);
|
self.pwm_core
|
||||||
|
.write_amplitude(self.dac.channel, self.dac.get_amplitude() as u8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// consumes self and runs
|
// /// consumes self and runs
|
||||||
|
|
@ -134,7 +123,6 @@ impl<'a, T: GeneralInstance16bit> InsertCoin<'a, T> {
|
||||||
// let mut delay = Delay;
|
// let mut delay = Delay;
|
||||||
// let tick_interval_us = 1000000/self.config.tick_rate_hz;
|
// let tick_interval_us = 1000000/self.config.tick_rate_hz;
|
||||||
|
|
||||||
|
|
||||||
// let mut led0_index = 0;
|
// let mut led0_index = 0;
|
||||||
// let led0_dcs = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
// let led0_dcs = [0u8, 25u8, 50u8, 75u8, 100u8, 75u8, 50u8, 25u8];
|
||||||
|
|
||||||
|
|
@ -144,7 +132,6 @@ impl<'a, T: GeneralInstance16bit> InsertCoin<'a, T> {
|
||||||
// loop {
|
// loop {
|
||||||
// self.dac.tick();
|
// self.dac.tick();
|
||||||
|
|
||||||
|
|
||||||
// if(self.led0.need_service()) {
|
// if(self.led0.need_service()) {
|
||||||
// self.led0.set_amplitude(led0_dcs[led0_index]);
|
// self.led0.set_amplitude(led0_dcs[led0_index]);
|
||||||
// self.pwm_core.write_amplitude(self.led0.channel, self.led0.amplitude);
|
// self.pwm_core.write_amplitude(self.led0.channel, self.led0.amplitude);
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,8 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||||
pwm.set_polarity(led0_ch, OutputPolarity::ActiveLow);
|
pwm.set_polarity(led0_ch, OutputPolarity::ActiveLow);
|
||||||
pwm.set_polarity(led1_ch, OutputPolarity::ActiveLow);
|
pwm.set_polarity(led1_ch, OutputPolarity::ActiveLow);
|
||||||
|
|
||||||
let sample_rate_hz = 16000;
|
let sample_rate_hz = 4000;
|
||||||
|
// let sample_rate_hz = 16000;
|
||||||
let dac_tick_per_service = 5;
|
let dac_tick_per_service = 5;
|
||||||
let tick_rate_hz = sample_rate_hz * dac_tick_per_service;
|
let tick_rate_hz = sample_rate_hz * dac_tick_per_service;
|
||||||
|
|
||||||
|
|
@ -374,10 +375,10 @@ fn app_main(mut p: hal::Peripherals, mut delay: Delay) -> ! {
|
||||||
let tick_interval_us = 1000000 / interfaces.config.tick_rate_hz - 10;
|
let tick_interval_us = 1000000 / interfaces.config.tick_rate_hz - 10;
|
||||||
|
|
||||||
// dac data
|
// dac data
|
||||||
// let coin_sound = include_bytes!("../audio/coin.raw");
|
// let coin_sound = include_bytes!("../audio/coin2.raw");
|
||||||
// let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
// let coin_sound = include_bytes!("../audio/sweep_dpcm_u4.raw");
|
||||||
|
|
||||||
let coin_sound = include_bytes!("../audio/button_1.raw");
|
let coin_sound = include_bytes!("../audio/button_1.raw");
|
||||||
|
|
||||||
let button_sound_1 = include_bytes!("../audio/button_1.raw");
|
let button_sound_1 = include_bytes!("../audio/button_1.raw");
|
||||||
let button_sound_2 = include_bytes!("../audio/button_2.raw");
|
let button_sound_2 = include_bytes!("../audio/button_2.raw");
|
||||||
let button_sound_3 = include_bytes!("../audio/button_3.raw");
|
let button_sound_3 = include_bytes!("../audio/button_3.raw");
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ pub fn clear_interrupt(coin_pin: u8, button_pin: u8) -> crate::InputFlags {
|
||||||
if (bits & (0x1 << button_pin)) != 0x0 {
|
if (bits & (0x1 << button_pin)) != 0x0 {
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("main_btn irq!");
|
println!("main_btn irq!");
|
||||||
|
input_flags.main_btn_flag = true;
|
||||||
// CHECK PC6
|
// CHECK PC6
|
||||||
// unsafe {
|
// unsafe {
|
||||||
// let mut val = 0;
|
// let mut val = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue