avr-something

Something something AVR side…
git clone git://henryandlizzy.uk/avr-something
Log | Files | Refs | README

main.cpp (1938B)


      1 #include "hidModule.h"
      2 #include "lcd.h"
      3 #include "timer.h"
      4 #include "ctrl.h"
      5 
      6 #include <avr/interrupt.h>
      7 #include <util/delay.h>
      8 
      9 
     10 
     11 int8_t const sinTable[] [[gnu::progmem]] =
     12 {
     13 	0,	3,	6,	9,	12,	16,	19,	22,
     14 	25,	28,	31,	34,	37,	40,	43,	46,
     15 	49,	51,	54,	57,	60,	63,	65,	68,
     16 	71,	73,	76,	78,	81,	83,	85,	88,
     17 	90,	92,	94,	96,	98,	100,102,104,
     18 	106,107,109,111,112,113,115,116,
     19 	117,118,120,121,122,122,123,124,
     20 	125,125,126,126,126,127,127,127
     21 };
     22 
     23 int main(void) 
     24 {
     25 	ctrl::disableJTAG();
     26 	hid::init();
     27 	lcd::init();
     28 
     29 	lcd::testFont();
     30 
     31 	io::direction::D() |= bits(5, 6, 7);
     32 
     33 	timer::two::outputCompareA() = 0x80;
     34 	timer::two::outputCompareB() = 0x80;
     35 	timer::two::control() = 0b00'00'0'001'1111'00'11;
     36 
     37 	for (;;)
     38 	{
     39 	//	LEDs
     40 
     41 		auto val = hid::sampleInput();
     42 
     43 		const auto r = (val & (hid::buttonL | hid::wheelA)) ? hid::ledRED : 0;
     44 		const auto y = (val & (hid::buttonD | hid::buttonU)) ? hid::ledYEL : 0;
     45 		const auto g = (val & (hid::buttonR | hid::wheelB)) ? hid::ledGRN : 0;
     46 
     47 		const auto leds = r | y | g;
     48 
     49 		hid::setLeds((val & hid::buttonC) ? ~leds : leds);
     50 
     51 	//	Sound
     52 
     53 		constexpr uint8_t midPoint = 127;
     54 		constexpr auto begin = flashPtr<int8_t>(sinTable);
     55 		constexpr auto end = begin + 64;
     56 		auto ptr = flashPtr<int8_t>(sinTable);
     57 		do
     58 		{
     59 			auto val = midPoint + ptr.load_post_inc();
     60 			timer::two::outputCompareA() = val;
     61 			timer::two::outputCompareB() = val;
     62 			_delay_us(10);
     63 		}
     64 		while (ptr != end);
     65 
     66 		while (ptr != begin)
     67 		{
     68 			auto val = midPoint + (--ptr).load();
     69 			timer::two::outputCompareA() = val;
     70 			timer::two::outputCompareB() = val;
     71 			_delay_us(10);
     72 		}
     73 
     74 		do
     75 		{
     76 			auto val = midPoint - ptr.load_post_inc();
     77 			timer::two::outputCompareA() = val;
     78 			timer::two::outputCompareB() = val;
     79 			_delay_us(10);
     80 		}
     81 		while (ptr != end);
     82 
     83 		while (ptr != begin)
     84 		{
     85 			auto val = midPoint - (--ptr).load();
     86 			timer::two::outputCompareA() = val;
     87 			timer::two::outputCompareB() = val;
     88 			_delay_us(10);
     89 		}
     90 	}
     91 
     92 }