bullshit commit, sync for travel (to zn00H!) :) master
authorhackbard <hackbard@staubsauger.localdomain>
Fri, 12 Oct 2007 12:52:32 +0000 (14:52 +0200)
committerhackbard <hackbard@staubsauger.localdomain>
Fri, 12 Oct 2007 12:52:32 +0000 (14:52 +0200)
betty/betty.c
betty/interrupts.c
betty/interrupts.h
betty/pffs.c
betty/pffs.h
betty/pwm.h
betty/system.c

index 24ea2eb..3a3e7a5 100644 (file)
@@ -38,14 +38,31 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) {
        }
 }
 
+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) {
@@ -117,6 +134,9 @@ 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;
@@ -191,18 +211,19 @@ int main() {
 
        // 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;
        
 
index 24159c0..7d319db 100644 (file)
@@ -211,14 +211,21 @@ void interrupt_tc_ir_set(u8 tcnum,u8 tcmc) {
        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
index 0ce073b..9da41e0 100644 (file)
 #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
@@ -118,6 +126,7 @@ void interrupt_tc_config(u8 tcnum,u8 mode,u8 cap,u32 psc);
 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);
 
index 7ba2232..93351bd 100644 (file)
@@ -148,9 +148,7 @@ int pffs_rearrange(t_pffs *pffs) {
        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)) {
@@ -158,12 +156,7 @@ int pffs_flash_register(t_pffs *pffs,u32 base_addr,u32 *sec_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;
index 98ddd50..5849fa7 100644 (file)
 
 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);
@@ -78,7 +77,6 @@ typedef struct s_pffs {
 
        /* pffs internal variables */
        u8 state;
-       u8 index_sec;                   // current index sector
        u8 data_tmp_sec;                // current temp data sector
 } t_pffs;
 
@@ -105,9 +103,7 @@ typedef struct s_pffs_file_header {
 }
 
 /* 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));
index 9d1903f..0d70f2d 100644 (file)
@@ -12,7 +12,9 @@
 #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
index 7554373..b181733 100644 (file)
@@ -65,6 +65,7 @@ void pin_init(void) {
         *
         * uart0: tx, rx
         * p0.7: pwm2
+        * p0.11: gpio -> audio (leave as is)
         *
         */
 
@@ -108,8 +109,14 @@ void pin_init(void) {
         * 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));