diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/test-timers.cpp | 143 | ||||
-rw-r--r-- | examples/vga-leaf.cpp | 138 | ||||
-rw-r--r-- | examples/vga-scope.cpp | 28 |
3 files changed, 50 insertions, 259 deletions
diff --git a/examples/test-timers.cpp b/examples/test-timers.cpp index c3e3cb9..374b903 100644 --- a/examples/test-timers.cpp +++ b/examples/test-timers.cpp @@ -2,7 +2,6 @@ // and turns on PWM on pin 2 #include "wirish.h" -#include "timers.h" #define LED_PIN 13 #define PWM_PIN 2 @@ -12,12 +11,8 @@ void handler2(void); void handler3(void); void handler4(void); -void setup_test_timer(void); - int toggle = 0; -int timer = 1; -int state = 3; -int last_but = 0; +int t; int count1 = 0; int count2 = 0; @@ -25,13 +20,15 @@ int count3 = 0; int count4 = 0; uint16 rate1 = 1000; uint16 rate2 = 2000; -uint16 rate3 = 3000; -uint16 rate4 = 4000; +uint16 rate3 = 4000; +uint16 rate4 = 8000; uint16 val1 = 10000; uint16 val2 = 10000; uint16 val3 = 10000; uint16 val4 = 10000; +HardwareTimer Timers[] = {Timer1, Timer2, Timer3, Timer4}; + void setup() { /* Set up the LED to blink */ @@ -42,123 +39,59 @@ void setup() /* Send a message out USART2 */ //SerialUSB.begin(9600); SerialUSB.println("Begining timer test..."); - - /* Send a message out the usb virtual serial port */ - //SerialUSB.println("Hello!"); - - timer = 1; - setup_test_timer(); - + for(int t=0; t<4; t++) { + Timers[t].setChannel1Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel2Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel3Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel4Mode(TIMER_OUTPUTCOMPARE); + } } - void loop() { - toggle ^= 1; - digitalWrite(LED_PIN, toggle); - delay(800); - - - if(digitalRead(38) && !last_but) { - state++; - switch(state){ - case 1: - SerialUSB.println("Testing Timer1 ---------------------------"); - timer = 1; - setup_test_timer(); - break; - case 2: - SerialUSB.println("Testing Timer2 ---------------------------"); - timer_set_mode(timer,1,TIMER_DISABLED); - timer_set_mode(timer,2,TIMER_DISABLED); - timer_set_mode(timer,3,TIMER_DISABLED); - timer_set_mode(timer,4,TIMER_DISABLED); - timer_set_count(1,0); - timer_set_count(2,0); - timer_set_count(3,0); - timer_set_count(4,0); - timer = 2; - setup_test_timer(); - break; - case 3: - SerialUSB.println("Testing Timer3 ---------------------------"); - timer_set_mode(timer,1,TIMER_DISABLED); - timer_set_mode(timer,2,TIMER_DISABLED); - timer_set_mode(timer,3,TIMER_DISABLED); - timer_set_mode(timer,4,TIMER_DISABLED); - timer = 3; - setup_test_timer(); - break; - case 4: - SerialUSB.println("Testing Timer4 ---------------------------"); - timer_set_mode(timer,1,TIMER_DISABLED); - timer_set_mode(timer,2,TIMER_DISABLED); - timer_set_mode(timer,3,TIMER_DISABLED); - timer_set_mode(timer,4,TIMER_DISABLED); - timer = 4; - setup_test_timer(); - break; - default: - state = 0; - timer_set_mode(timer,1,TIMER_DISABLED); - timer_set_mode(timer,2,TIMER_DISABLED); - timer_set_mode(timer,3,TIMER_DISABLED); - timer_set_mode(timer,4,TIMER_DISABLED); - timer = 0; - SerialUSB.println("Restarting -------------------------------"); - } + for(t=0; t<4; t++) { + toggle ^= 1; digitalWrite(LED_PIN, toggle); + delay(1000); + SerialUSB.println("-----------------------------------------------------"); + SerialUSB.print("Testing Timer "); SerialUSB.println(t+1); + count1 = count2 = count3 = count4 = 0; + Timers[t].setChannel1Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel2Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel3Mode(TIMER_OUTPUTCOMPARE); + Timers[t].setChannel4Mode(TIMER_OUTPUTCOMPARE); + Timers[t].attachCompare1Interrupt(handler1); + Timers[t].attachCompare2Interrupt(handler2); + Timers[t].attachCompare3Interrupt(handler3); + Timers[t].attachCompare4Interrupt(handler4); + delay(5000); + Timers[t].setChannel1Mode(TIMER_DISABLED); + Timers[t].setChannel2Mode(TIMER_DISABLED); + Timers[t].setChannel3Mode(TIMER_DISABLED); + Timers[t].setChannel4Mode(TIMER_DISABLED); + SerialUSB.print("Count1: "); SerialUSB.println(count1); + SerialUSB.print("Count2: "); SerialUSB.println(count2); + SerialUSB.print("Count3: "); SerialUSB.println(count3); + SerialUSB.print("Count4: "); SerialUSB.println(count4); } - - SerialUSB.print("Doing ------------------ "); SerialUSB.println(timer,DEC); - if(timer!=0) { SerialUSB.print("CNT: "); SerialUSB.println(timer_get_count(timer),DEC); } - SerialUSB.print("Count1 : "); SerialUSB.println(count1,DEC); - SerialUSB.print("Count2 : "); SerialUSB.println(count2,DEC); - SerialUSB.print("Count3 : "); SerialUSB.println(count3,DEC); - SerialUSB.print("Count4 : "); SerialUSB.println(count4,DEC); - SerialUSB.println(); - /* - SerialUSB.print("Status : "); SerialUSB.println(get_sr(),HEX); - */ - last_but = digitalRead(38); -} - -void setup_test_timer(void) { - timer_set_prescaler(timer,10000); - timer_set_mode(timer,1,TIMER_OUTPUTCOMPARE); - timer_set_mode(timer,2,TIMER_OUTPUTCOMPARE); - timer_set_mode(timer,3,TIMER_OUTPUTCOMPARE); - timer_set_mode(timer,4,TIMER_OUTPUTCOMPARE); - val1 = val2 = val3 = val4 = 10000; - timer_set_compare_value(timer,1,val1); - timer_set_compare_value(timer,2,val2); - timer_set_compare_value(timer,3,val3); - timer_set_compare_value(timer,4,val4); - timer_attach_interrupt(timer,1,handler1); - timer_attach_interrupt(timer,2,handler2); - timer_attach_interrupt(timer,3,handler3); - timer_attach_interrupt(timer,4,handler4); - count1 = count2 = count3 = count4 = 0; } void handler1(void) { val1 += rate1; - timer_set_compare_value(timer,1,val1); + Timers[t].setCompare1(val1); count1++; - //SerialUSB.print("CC3 Inter: "); SerialUSB.print(get_sr(),HEX); - // SerialUSB.print(", "); SerialUSB.println(get_sr_buff(),HEX); } void handler2(void) { val2 += rate2; - timer_set_compare_value(timer,2,val2); + Timers[t].setCompare2(val2); count2++; } void handler3(void) { val3 += rate3; - timer_set_compare_value(timer,3,val3); + Timers[t].setCompare3(val3); count3++; } void handler4(void) { val4 += rate4; - timer_set_compare_value(timer,4,val4); + Timers[t].setCompare4(val4); count4++; } diff --git a/examples/vga-leaf.cpp b/examples/vga-leaf.cpp index c2e61ae..3374608 100644 --- a/examples/vga-leaf.cpp +++ b/examples/vga-leaf.cpp @@ -1,39 +1,11 @@ - #include "wirish.h" -/* -D5 PB6 - TIM4_CH1 I2C1_SCL - - Y -D6 PA8 - TIM1_CH1 - USART1_CK - Y -D7 PA9 - TIM1_CH2 - USART1_TX - Y -D8 PA10 - TIM1_CH3 - USART1_RX - Y -D9 PB7 - TIM4_CH2 I2C1_SDA - - Y -*/ - -//gpio_write_bit(GPIOB_BASE, 6, 1); // VGA_R -//gpio_write_bit(GPIOB_BASE, 6, 0); - -//(GPIOA_BASE)->BSRR = BIT(8); -//asm volatile("nop"); -//(GPIOA_BASE)->BRR = BIT(8); -/* - gpio_write_bit(GPIOB_BASE, 6, 1); // VGA_R - gpio_write_bit(GPIOB_BASE, 6, 0); - gpio_write_bit(GPIOA_BASE, 8, 1); // VGA_G - gpio_write_bit(GPIOA_BASE, 8, 0); - gpio_write_bit(GPIOA_BASE, 9, 1); // VGA_B - gpio_write_bit(GPIOA_BASE, 9, 0); - gpio_write_bit(GPIOA_BASE, 10, 1); // VGA_V - gpio_write_bit(GPIOA_BASE, 10, 0); - gpio_write_bit(GPIOB_BASE, 7, 1); // VGA_H - gpio_write_bit(GPIOB_BASE, 7, 0); -*/ - #define LED_PIN 13 -#define VGA_R 5 // B6 -#define VGA_G 6 // A8 -#define VGA_B 7 // A9 -#define VGA_V 11 // A6 -#define VGA_H 12 // A7 +#define VGA_R 5 // B6 +#define VGA_G 6 // A8 +#define VGA_B 7 // A9 +#define VGA_V 11 // A6 +#define VGA_H 12 // A7 #define VGA_R_HIGH (GPIOB_BASE)->BSRR = BIT(6) #define VGA_R_LOW (GPIOB_BASE)->BRR = BIT(6) #define VGA_G_HIGH (GPIOA_BASE)->BSRR = BIT(8) @@ -89,11 +61,14 @@ void setup() timer_set_count(4,0); } +void loop() { + // everything happens in the interrupts! +} + int toggle = 0; -uint16 x = 0; +uint16 x = 0; uint16 y = 0; uint8 v_active = 1; -GPIO_Port *portb = GPIOB_BASE; void isr_porch(void) { VGA_H_HIGH; @@ -139,9 +114,9 @@ uint8 logo[18][16] = { void isr_start(void) { if(!v_active) { return; } + VGA_R_LOW; VGA_R_HIGH; - //delayMicroseconds(2); - //gpio_write_bit(GPIOA_BASE, 8, 1); // VGA_G + for(x=0; x<32; x++) { if(logo[y/28][x/2]) { VGA_G_HIGH; @@ -151,7 +126,6 @@ void isr_start(void) { VGA_B_LOW; } } - } void isr_stop(void) { if(!v_active) { return; } @@ -163,94 +137,6 @@ void isr_update(void) { VGA_H_LOW; } -void loop() { - /* - toggle ^= 1; - digitalWrite(LED_PIN, toggle); - delay(100); - Serial2.println("HIHIHI!"); - */ - //for(y=0; y<480; y++) { - /* - for(y=0; y<160; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_H_HIGH; - VGA_R_HIGH; - delayMicroseconds(8); - VGA_G_HIGH; - delayMicroseconds(10); - VGA_B_HIGH; - delayMicroseconds(10); - VGA_R_LOW; - VGA_B_LOW; - VGA_G_LOW; - //VGA_G_HIGH; - } - for(y=0; y<160; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_H_HIGH; - VGA_G_HIGH; - delayMicroseconds(8); - VGA_R_HIGH; - delayMicroseconds(10); - VGA_B_HIGH; - delayMicroseconds(10); - VGA_R_LOW; - VGA_B_LOW; - VGA_G_LOW; - //VGA_G_HIGH; - } - for(y=0; y<160; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_H_HIGH; - VGA_B_HIGH; - delayMicroseconds(8); - VGA_G_HIGH; - delayMicroseconds(10); - VGA_R_HIGH; - delayMicroseconds(10); - VGA_R_LOW; - VGA_B_LOW; - VGA_G_LOW; - //VGA_G_HIGH; - } - for(y=0; y<11; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_R_LOW; - VGA_H_HIGH; - delayMicroseconds(28); - } - VGA_V_LOW; - for(y=0; y<2; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_R_LOW; - VGA_H_HIGH; - delayMicroseconds(28); - } - VGA_V_HIGH; - for(y=0; y<30; y++) { - VGA_R_LOW; - VGA_H_LOW; - delayMicroseconds(3); - VGA_R_LOW; - VGA_H_HIGH; - delayMicroseconds(28); - } - */ - -} - - int main(void) { init(); setup(); diff --git a/examples/vga-scope.cpp b/examples/vga-scope.cpp index 1f597a4..3e7e75e 100644 --- a/examples/vga-scope.cpp +++ b/examples/vga-scope.cpp @@ -1,33 +1,6 @@ #include "wirish.h" -/* -D5 PB6 - TIM4_CH1 I2C1_SCL - - Y -D6 PA8 - TIM1_CH1 - USART1_CK - Y -D7 PA9 - TIM1_CH2 - USART1_TX - Y -D8 PA10 - TIM1_CH3 - USART1_RX - Y -D9 PB7 - TIM4_CH2 I2C1_SDA - - Y -*/ - -//gpio_write_bit(GPIOB_BASE, 6, 1); // VGA_R -//gpio_write_bit(GPIOB_BASE, 6, 0); - -//(GPIOA_BASE)->BSRR = BIT(8); -//asm volatile("nop"); -//(GPIOA_BASE)->BRR = BIT(8); -/* - gpio_write_bit(GPIOB_BASE, 6, 1); // VGA_R - gpio_write_bit(GPIOB_BASE, 6, 0); - gpio_write_bit(GPIOA_BASE, 8, 1); // VGA_G - gpio_write_bit(GPIOA_BASE, 8, 0); - gpio_write_bit(GPIOA_BASE, 9, 1); // VGA_B - gpio_write_bit(GPIOA_BASE, 9, 0); - gpio_write_bit(GPIOA_BASE, 10, 1); // VGA_V - gpio_write_bit(GPIOA_BASE, 10, 0); - gpio_write_bit(GPIOB_BASE, 7, 1); // VGA_H - gpio_write_bit(GPIOB_BASE, 7, 0); -*/ - #define LED_PIN 13 #define ANALOG_PIN 18 #define VGA_R 5 // B6 @@ -152,7 +125,6 @@ void isr_update(void) { void loop() { //val = analogRead(ANALOG_PIN); - } |