}
}
+void audio_mute_toggle(void) {
+
+ if(IOPIN0&(1<<11))
+ IOCLR0=(1<<11);
+ else
+ IOSET0=(1<<11);
+}
+
+#define AUDIO_TONE_C (7500000/(262*256))
+#define AUDIO_TONE_D (7500000/(294*256))
+#define AUDIO_TONE_E (7500000/(330*256))
+#define AUDIO_TONE_F (7500000/(349*256))
+#define AUDIO_TONE_G (7500000/(392*256))
+//#define AUDIO_TONE_A (7500000/(440*256))
+#define AUDIO_TONE_A 120
+#define AUDIO_TONE_H (7500000/(494*256))
+
void __attribute__ ((interrupt("IRQ"))) set_sample(void) {
- uart0_send_byte('S');
+ //uart0_send_byte('S');
pwm_update_match(PWM_CHAN2,PWM_SINGLE_EDGE,sinus[sample_count++],0);
if(sample_count==0xff)
sample_count=0;
interrupt_ack();
- interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0);
+ interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_MATCH0);
}
void __attribute__ ((interrupt("IRQ"))) input_event(void) {
display_string_page(10,8,(u8 *)d2_txt,
DISPLAY_FILL_B,0,8);
break;
+ case BUTTON_MUTE:
+ audio_mute_toggle();
+ break;
default:
display_clear_screen();
break;
// timer interrupt
interrupt_tc_config(INTERRUPT_TC0,INTERRUPT_TC_MODE_T,0,0);
- interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,120,
+ interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,AUDIO_TONE_A,
INTERRUPT_TC_MATCH_IR|
INTERRUPT_TC_MATCH_RESET);
interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_MATCH0);
interrupt_enable(INTERRUPT_TIMER0,INTERRUPT_MODE_VIRQ,
1,(u32)&set_sample);
+ interrupt_tc_enable(INTERRUPT_TC0);
/* pwm init */
+ pwm_reset;
pwm_set_rate_and_prescaler(0xff,0);
pwm_config(PWM_CHAN2,PWM_SINGLE_EDGE,0,0);
- pwm_match_ctrl_config(PWM_CHAN2,0);
- interrupt_pwm_ir_set(PWM_CHAN2);
+ pwm_match_ctrl_config(PWM_CHAN2,PWM_MATCH_RESET);
pwm_enable;
if(tcnum>1)
return;
- if(tcnum==0) {
+ if(tcnum==0)
T0IR=tcmc;
- T0TCR=0x01;
- }
- else {
+ else
T1IR=tcmc;
+}
+
+void interrupt_tc_enable(u8 tcnum) {
+
+ if(tcnum>1)
+ return;
+
+ if(tcnum==0)
+ T0TCR=0x01;
+ else
T1TCR=0x01;
- }
}
// pwm interrupts
#define INTERRUPT_CAP2 0x40
#define INTERRUPT_CAP3 0x80
+#define INTERRUPT_PWM0 0x01
+#define INTERRUPT_PWM1 0x02
+#define INTERRUPT_PWM2 0x04
+#define INTERRUPT_PWM3 0x08
+#define INTERRUPT_PWM4 0x10
+#define INTERRUPT_PWM5 0x20
+#define INTERRUPT_PWM6 0x40
+
#define INTERRUPT_SET 0x00
#define INTERRUPT_USED 0x01
#define INTERRUPT_PRIORITY_USED 0x02
void interrupt_tc_match_config(u8 tcnum,u8 mnum,u32 val,u8 mode);
void interrupt_tc_capt_config(u8 tcnum,u8 cnum,u8 mode);
void interrupt_tc_ir_set(u8 tcnum,u8 tcmc);
+void interrupt_tc_enable(u8 tcnum);
void interrupt_pwm_ir_set(u8 pwm_channel);
return 0;
}
-int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,
- u8 sec_num_data_min,u8 sec_num_data_max,
- u8 sec_num_index0,u8 sec_num_index1,
+int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,u8 sec_num,
int (*fw)(u32 addr,u16 *buf,int len),
int (*fr)(u32 addr,u16 *buf,int len),
int (*fe)(u32 addr)) {
/* assign physical flash specs */
pffs->base_addr=base_addr;
pffs->sec_addr=sec_addr;
-
- /* specified index and data sectors */
- pffs->sec_num_data[0]=sec_num_data_min;
- pffs->sec_num_data[1]=sec_num_data_max;
- pffs->sec_num_index[0]=sec_num_index0;
- pffs->sec_num_index[1]=sec_num_index1;
+ pffs->sec_num=sec_num;
/* flash acccess function pointers */
pffs->fw=fw;
typedef struct s_pffs {
/* flash specs */
- u32 base_addr;
- u32 *sec_addr;
- u8 sec_num_data[2]; // first/last sector used for data
- u8 sec_num_index[2]; // 2 sectors used as an index
+ u32 base_addr; // base flash access address
+ u32 *sec_addr; // pointer to sector addresses
+ u8 sec_num; // number of sectors
/* flash write, read and sector erase function pointers */
int (*fw)(u32 addr,u16 *buf,int len);
/* pffs internal variables */
u8 state;
- u8 index_sec; // current index sector
u8 data_tmp_sec; // current temp data sector
} t_pffs;
}
/* function prototypes (only the ones applications should use!) */
-int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,
- u8 sec_num_data_min,u8 sec_num_data_max,
- u8 sec_num_index0,u8 sec_num_index1,
+int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_addr,u8 sec_num,
int (*fw)(u32 addr,u16 *buf,int len),
int (*fr)(u32 addr,u16 *buf,int len),
int (*fe)(u32 addr));
#include "types.h"
/* macros */
-#define pwm_enable PWMTCR=0x0b
+#define pwm_enable PWMTCR=0x09
+#define pwm_reset PWMTCR=0x03
+#define pwm_disable PWMTCR=0x00
/* defines */
#define PWM_SINGLE_EDGE 0x00
*
* uart0: tx, rx
* p0.7: pwm2
+ * p0.11: gpio -> audio (leave as is)
*
*/
* out: p2.18 - p2.24 (+ pull high)
* in: p0.30, p0.{27,28}, p3.{20,21}, p0.22, p0.13
*
+ * audio:
+ *
+ * p0.11: out
+ *
*/
+ //IODIR0=(1<<11);
+
// nothing to do for inputs (default: 0x00000000)
IODIR2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));