--- /dev/null
+/*
+ * pwm.c - arm pwm interface
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#include "pwm.h"
+
+/*
+ * functions
+ */
+
+void pwm_set_rate_and_prescaler(u32 rate,u32 prescaler) {
+
+ PWMMR0=rate;
+ PWMPR=prescaler;
+}
+
+int pwm_config(u8 pwmchan,u8 mode,u32 val1,u32 val2) {
+
+ u32 *addr;
+
+ addr=(u32 *)&PWMMR0;
+
+ if((pwmchan>6)|(pwmchan<1))
+ return PWM_INVALID_CHAN;
+
+ if(mode==PWM_DOUBLE_EDGE) {
+ if(pwmchan&0x01)
+ return PWM_STUPID;
+ *((volatile u32 *)addr+pwmchan)=val2;
+ *((volatile u32 *)addr+pwmchan-1)=val1;
+ }
+
+ if(mode==PWM_SINGLE_EDGE)
+ *((volatile u32 *)addr+pwmchan)=val1;
+
+ PWMPCR=(PWMPCR&0x7e7c)|(mode<<(2+pwmchan))|(1<<(9+pwmchan));
+
+ return PWM_SET;
+}
+
+int pwm_update_match(u8 pwmchan,u8 mode,u32 val1,u32 val2) {
+
+ u32 *addr;
+
+ addr=(u32 *)&PWMMR0;
+
+ if((pwmchan>6)|(pwmchan<1))
+ return PWM_INVALID_CHAN;
+
+ if(mode==PWM_DOUBLE_EDGE) {
+ if(pwmchan&0x01)
+ return PWM_STUPID;
+ *((volatile u32 *)addr+pwmchan)=val2;
+ *((volatile u32 *)addr+pwmchan-1)=val1;
+ }
+
+ if(mode==PWM_SINGLE_EDGE)
+ *((volatile u32 *)addr+pwmchan)=val1;
+
+ return PWM_SET;
+}
+
+void pwm_match_ctrl_config(u8 matchreg,u8 ctrl) {
+
+ PWMMCR=(PWMMCR&0x1fffff)|(ctrl<<(3*matchreg));
+}
+
--- /dev/null
+/*
+ * pwm.h - arm pwm interface header file
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#ifndef PWM_H
+#define PWM_H
+
+#include "lpc2xxx.h"
+#include "types.h"
+
+/* macros */
+#define pwm_enable PWMTCR=0x0b
+
+/* defines */
+#define PWM_SINGLE_EDGE 0x00
+#define PWM_DOUBLE_EDGE 0x01
+
+#define PWM_MATCH_INTERRUPT 0x01
+#define PWM_MATCH_RESET 0x02
+#define PWM_MATCH_STOP 0x04
+
+#define PWM_SET 0x00
+#define PWM_INVALID_CHAN 0x01
+#define PWM_STUPID 0x02
+
+#define PWM_CHAN0 0
+#define PWM_CHAN1 1
+#define PWM_CHAN2 2
+#define PWM_CHAN3 3
+#define PWM_CHAN4 4
+#define PWM_CHAN5 5
+#define PWM_CHAN6 6
+
+/* function prototypes */
+
+void pwm_set_rate_and_prescaler(u32 rate,u32 prescaler);
+int pwm_config(u8 pwmchan,u8 mode,u32 val1,u32 val2);
+int pwm_update_match(u8 pwmchan,u8 mode,u32 val1,u32 val2);
+void pwm_match_ctrl_config(u8 matchreg,u8 ctrl);
+
+#endif