Commit 09f5388c authored by medlem's avatar medlem

Finished task2 LF. Still in copy

parent 9a4c5ad3
......@@ -166,6 +166,12 @@
<Compile Include="main.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="graphics.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="graphics.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="spi.c">
<SubType>compile</SubType>
</Compile>
......
......@@ -8,7 +8,7 @@
#include <avr/io.h>
void adc_init(){
ADC0.CTRLA |= (ADC_RESSEL_10BIT_gc); //Set resolution, we choose 8 bits
ADC0.CTRLA |= (ADC_RESSEL_10BIT_gc); //Set resolution, we choose 10 bits
ADC0.CTRLB |= (ADC_SAMPNUM_ACC4_gc); //OPTIONAL: We can use multiple samples if we like, example here with 4
//More samples gives a better result but takes longer.
......
......@@ -4,8 +4,6 @@
* Created: 27.02.2017 16:51:27
* Author: Petter
*/
#ifndef ADC_H_
#define ADC_H_
......
#include "oled.h"
#include "graphics.h"
/* Draw the outline of the loading bar */
void graphics_loading_bar_init()
{
oled_pos(1,12);
oled_write_d(0xf8);
oled_pos(2,12);
oled_write_d(0x1f);
oled_pos(1,115);
oled_write_d(0xf8);
oled_pos(2,115);
oled_write_d(0x1f);
for(uint8_t i=0;i<101;i++)
{
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
}
/* Set length of loading bar. Between 0 and 1023 */
void graphics_loading_bar_set(uint16_t data)
{
if(data>1023){ //Highest data value
data=1023;
}
data=data/10; //convert data to percentages
for(int i=0; i<data;i++){
oled_pos(1,13+i);
oled_write_d(0xf8);
oled_pos(2,13+i);
oled_write_d(0x1f);
}
for(int i=data; i<102;i++){
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
}
/* Print bitmap to screen */
void graphics_print_bitmap(const uint8_t* bm)
{
for(uint8_t y = 0; y < 4; y++)
{
for(uint8_t x = 0; x < 16; x++)
{
uint8_t d[8] = {
pgm_read_byte(&(bm[(8 * y + 0) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 1) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 2) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 3) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 4) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 5) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 6) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 7) * 16 + x]))
};
for(uint8_t b = 0; b < 8; b++)
{
uint8_t db = 0;
db |= (((d[0] >> b) & 0x1) << 0);
db |= (((d[1] >> b) & 0x1) << 1);
db |= (((d[2] >> b) & 0x1) << 2);
db |= (((d[3] >> b) & 0x1) << 3);
db |= (((d[4] >> b) & 0x1) << 4);
db |= (((d[5] >> b) & 0x1) << 5);
db |= (((d[6] >> b) & 0x1) << 6);
db |= (((d[7] >> b) & 0x1) << 7);
oled_write_d(db);
}
}
}
}
\ No newline at end of file
/*
* oled_graphic.h
*
* Created: 11.03.2019 20:30:38
* Author: medlem
*/
#ifndef OLED_GRAPHIC_H_
#define OLED_GRAPHIC_H_
#include <avr/io.h>
#include <avr/pgmspace.h>
/* Draw the outline of the loading bar */
void graphics_loading_bar_init();
/* Set length of loading bar. Between 0 and 1023 */
void graphics_loading_bar_set(uint16_t data);
/* Print a bitmap to the screen. See Graphics section under to find example bitmap. */
void graphics_print_bitmap(const uint8_t* bm);
//Graphics. Probably generated on the Internet.
static const uint8_t PROGMEM OV[512] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x70, 0x38, 0xDE, 0x3F, 0x3E, 0x18, 0x00, 0x00,
0x00, 0xF0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x78, 0xDE, 0x3B, 0x33, 0x1C, 0x00, 0x00,
0x00, 0xFC, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8E, 0x21, 0x23, 0x1C, 0x00, 0x00,
0x00, 0xFE, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8E, 0xA9, 0x23, 0x3C, 0x00, 0x00,
0x00, 0x3F, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8F, 0x89, 0x03, 0x3C, 0x00, 0x00,
0x00, 0x1F, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8D, 0x8F, 0x03, 0x36, 0x00, 0x00,
0x80, 0x0F, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0x8C, 0xF9, 0x8D, 0x8B, 0x7B, 0x32, 0x00, 0x00,
0xC0, 0x07, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0x89, 0x33, 0x3E, 0x00, 0x00,
0xC0, 0x03, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0xA1, 0x33, 0x72, 0x00, 0x00,
0xE0, 0x03, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0xA1, 0x33, 0x72, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xD8, 0xD9, 0x8D, 0x31, 0x33, 0x63, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xDE, 0x3F, 0x3F, 0xF7, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0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, 0x66, 0x98, 0x19, 0xC3, 0x60, 0xC8, 0x1C,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x0E, 0x47, 0x66, 0x98, 0x1B, 0xC2, 0x60, 0xC8, 0x0C,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x0E, 0x47, 0x6E, 0x99, 0x1B, 0xC3, 0x61, 0xCC, 0x0C,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x8E, 0x7F, 0xFF, 0xBD, 0xFF, 0xE3, 0xF3, 0xEF, 0x07,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif /* OLED_GRAPHIC_H_ */
\ No newline at end of file
......@@ -13,196 +13,61 @@
#include <avr/interrupt.h>
#include "oled.h"
#include "oled.h" //TODO abstraher oled
#include "adc.h"
#include "graphics.h"
#include "spi.h"
const uint8_t OV[512] PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x70, 0x38, 0xDE, 0x3F, 0x3E, 0x18, 0x00, 0x00,
0x00, 0xF0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x78, 0xDE, 0x3B, 0x33, 0x1C, 0x00, 0x00,
0x00, 0xFC, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8E, 0x21, 0x23, 0x1C, 0x00, 0x00,
0x00, 0xFE, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8E, 0xA9, 0x23, 0x3C, 0x00, 0x00,
0x00, 0x3F, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8F, 0x89, 0x03, 0x3C, 0x00, 0x00,
0x00, 0x1F, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x8C, 0x79, 0x8D, 0x8F, 0x03, 0x36, 0x00, 0x00,
0x80, 0x0F, 0x00, 0xE0, 0x03, 0x00, 0x00, 0x00, 0x8C, 0xF9, 0x8D, 0x8B, 0x7B, 0x32, 0x00, 0x00,
0xC0, 0x07, 0x00, 0xC0, 0x07, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0x89, 0x33, 0x3E, 0x00, 0x00,
0xC0, 0x03, 0x00, 0x80, 0x07, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0xA1, 0x33, 0x72, 0x00, 0x00,
0xE0, 0x03, 0x00, 0x80, 0x0F, 0x00, 0x00, 0x00, 0x8C, 0xD9, 0x8D, 0xA1, 0x33, 0x72, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xD8, 0xD9, 0x8D, 0x31, 0x33, 0x63, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0xF8, 0xFC, 0xDE, 0x3F, 0x3F, 0xF7, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xFF, 0xC7, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xE0, 0xE1, 0x00, 0x0E, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x0E, 0x47, 0x6E, 0x99, 0x1B, 0xC3, 0x61, 0xCC, 0x0C,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x8E, 0x7F, 0xFF, 0xBD, 0xFF, 0xE3, 0xF3, 0xEF, 0x07,
0xFE, 0x7F, 0xFE, 0xFD, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define KLAKK 0x00
#define LED0_bm 0x20
#define LED0_PORT PORTF
#define FONTSIZE 5
#define ADC_PRINT_START 82
#define SW0_bm 0x40
#define SW0_PORT PORTF
int main(void)
{
sei();
_delay_ms(500);
uint16_t data;
SW0_PORT.DIRCLR = SW0_bm;
SPI_MasterInit();
oled_init();
adc_init();
oled_write_bitmap(OV); //Printing Bitmap
graphics_print_bitmap(OV); //Printing Bitmap for startup swag.
_delay_ms(2000);
oled_clear_screen();
LED0_PORT.DIRSET = LED0_bm;
SW0_PORT.DIRCLR = SW0_bm;
oled_pos(1,12);
oled_write_d(0xf8);
oled_pos(2,12);
oled_write_d(0x1f);
oled_pos(1,115);
oled_write_d(0xf8);
oled_pos(2,115);
oled_write_d(0x1f);
for(uint8_t i=0;i<101;i++)
{
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
oled_pos(0,12);
fprintf(FONT5,"OV-POT read: ");
uint8_t software_timer_print_adc = 0;
uint8_t blinkled = 0;
uint16_t data;
uint16_t percent_data;
graphics_loading_bar_init();
while (1)
{
software_timer_print_adc++;
blinkled++;
uint8_t adc_curser_position=82;
data=adc_read(KLAKK)/4;
data=adc_read(KLAKK)/4; //update data each loop using polling. TCA timer interrupt would have been smoother.
oled_pos(0,12);
fprintf(FONT5,"OV-POT read: ");
fprintf(FONT5,"%4u",data); //Fancy formatting for better user experience
//Update loading bar
graphics_loading_bar_set(data);
if (software_timer_print_adc==2)
{
oled_pos(0,ADC_PRINT_START);
//for (uint8_t i=0;i<27;i++)
//{
// oled_write_d(0x00);
//}
// if (data>=1000)
// {
oled_pos(0,adc_curser_position);
// }
if (data<1000)
{
for (uint8_t i=0;i<FONTSIZE;i++)
{
oled_write_d(0x00);
}
adc_curser_position+=FONTSIZE+1;
oled_pos(0,adc_curser_position);
}
if (data<100)
{
for (uint8_t i=0;i<FONTSIZE;i++)
{
oled_write_d(0x00);
}
adc_curser_position+=FONTSIZE+1;
oled_pos(0,adc_curser_position);
}
if (data<10)
{
for (uint8_t i=0;i<FONTSIZE;i++)
{
oled_write_d(0x00);
}
adc_curser_position+=FONTSIZE+1;
oled_pos(0,adc_curser_position);
}
fprintf(FONT5," %u",data);
software_timer_print_adc=0;
}
percent_data=data/10;
for(int i=0; i<percent_data;i++){
oled_pos(1,13+i);
oled_write_d(0xf8);
oled_pos(2,13+i);
oled_write_d(0x1f);
}
for(int i=percent_data; i<102;i++){
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
if (blinkled==15)
{
PORTF.OUTTGL = LED0_bm;
blinkled=0;
}
//Voltage printout
oled_pos(3,12);
//uint32_t voltage=
uint8_t voltage_integer= data*323ul/100000ul;
uint8_t voltage_integer= data*323ul/100000ul; //This is a lot faster than floats. Compiler magic
uint8_t voltage_fraction= (data*323ul%100000ul)/1000;
fprintf(FONT5,"Voltage: %u.%02u V",voltage_integer,voltage_fraction);
//Extra function for dopeness
if (!(SW0_PORT.IN & (SW0_bm)))
{
oled_pos(0,0);
oled_write_bitmap(OV);
graphics_print_bitmap(OV);
while (!(SW0_PORT.IN & (SW0_bm)))
{
}
oled_clear_screen();
oled_pos(1,12);
oled_write_d(0xf8);
oled_pos(2,12);
oled_write_d(0x1f);
oled_pos(1,115);
oled_write_d(0xf8);
oled_pos(2,115);
oled_write_d(0x1f);
for(uint8_t i=0;i<101;i++)
{
oled_pos(1,13+i);
oled_write_d(0x08);
oled_pos(2,13+i);
oled_write_d(0x10);
}
oled_pos(0,12);
fprintf(FONT5,"OV-POT read: ");
graphics_loading_bar_init();
}
}
}
/*
* OLED.c
*
* Created: 17.09.2015 12:22:09
* Author: helgeanl
*/
#define F_CPU 3333333ul
#include <avr/io.h>
#include <avr/pgmspace.h>
......@@ -12,7 +5,6 @@
#include <stdbool.h>
#include "oled.h"
#include "fonts.h"
#include "spi.h"
//#include "display.h"
......@@ -32,11 +24,10 @@ uint8_t oled_get_current_line(){
return oled_current_line_num;
}
void oled_init()
void oled_init() // Documentation on oled screen on: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
{
OLED_RESET_PORT.DIRSET = OLED_RESET_bm;
OLED_MODE_PORT.DIRSET = OLED_MODE_bm;
SPI_MasterInit();
oled_set_mode(1);
oled_reset();
......@@ -99,6 +90,7 @@ void oled_init()
oled_clear_screen();
}
/* Hardware reset the screen */
void oled_reset()
{
......@@ -109,7 +101,6 @@ void oled_reset()
}
/* Set data/command mode */
void oled_set_mode(uint8_t mode)
{
if (mode == DATA_MODE)
......@@ -121,11 +112,13 @@ void oled_set_mode(uint8_t mode)
OLED_MODE_PORT.OUTCLR=OLED_MODE_bm;
}
}
/* Write command */
void oled_write_c(uint8_t command){
oled_set_mode(0);
SPI_MasterTransmit(command);
}
/* Write data*/
void oled_write_d(uint8_t data){
oled_set_mode(1);
......@@ -205,112 +198,3 @@ void oled_set_brightness(uint8_t lvl){
oled_write_c(0x81); // Set brightness command
oled_write_c(lvl); // Set brightness level
}
/* Print an arrow at given position*/
void oled_print_arrow(uint8_t row, uint8_t col)
{
oled_pos(row,col);
oled_write_d(0b00011000);
oled_write_d(0b00011000);
oled_write_d(0b01111110);
oled_write_d(0b00111100);
oled_write_d(0b00011000);
}
/* Print a backarrow at given position*/
void oled_print_backarrow(uint8_t row, uint8_t col)
{
oled_pos(row, col);
oled_write_d(0b00011000);
oled_write_d(0b00011000);
oled_write_d(0b01111110);
oled_write_d(0b00111100);
oled_write_d(0b00011000);
}
/* Print Game Over image found in progmem */
void oled_print_game_over()
{
for(uint8_t i = 0; i < 8; i++){
oled_pos(i, 0);
for (uint8_t j=0; j < 128; j++) {
oled_write_d(pgm_read_word(&game_over_img[i*128 + j]));
}
}
}
/* Print the Pong startup image */
void oled_print_pong()
{
for(uint8_t i = 0; i < 8; i++){
oled_pos(i, 0);
for (uint8_t j=0; j < 128; j++) {
oled_write_d(pgm_read_word(&pong_img[i*128 + j]));
}
}
}
void oled_write_bitmap(const uint8_t* bm)
{
for(uint8_t y = 0; y < 4; y++)
{
for(uint8_t x = 0; x < 16; x++)
{
uint8_t d[8] = {
pgm_read_byte(&(bm[(8 * y + 0) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 1) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 2) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 3) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 4) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 5) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 6) * 16 + x])),
pgm_read_byte(&(bm[(8 * y + 7) * 16 + x]))
};
for(uint8_t b = 0; b < 8; b++)
{
uint8_t db = 0;
db |= (((d[0] >> b) & 0x1) << 0);
db |= (((d[1] >> b) & 0x1) << 1);
db |= (((d[2] >> b) & 0x1) << 2);
db |= (((d[3] >> b) & 0x1) << 3);
db |= (((d[4] >> b) & 0x1) << 4);
db |= (((d[5] >> b) & 0x1) << 5);
db |= (((d[6] >> b) & 0x1) << 6);
db |= (((d[7] >> b) & 0x1) << 7);
oled_write_d(db);
}
}
}
}
// Menu
// - Start new game
// - See/reset
// - highscore
// - Calibrate joystick
// - Set difficulty
// - Debugging
//////////////////////////////////////////////////////////////////////////
//void test(){
//const char FlashString[] PROGMEM = "This is a string held completely in flash memory.";
//// -> LCD_puts(PSTR("Program Memory String"));
//}
//
//static unsigned int LCD_SegTable[] PROGMEM =
//{
//0xEAA8, // '*'
//0x2A80, // '+'
//0x4000, // ','
//0x0A00, // '-'
//0x0A51, // '.' Degree sign
//0x4008, // '/'
//}
......@@ -33,7 +33,6 @@ void oled_clear_screen();
/* Clear one line */
void oled_clear_line(uint8_t line);
/* Go to given row*/
void oled_goto_line(uint8_t line);
......@@ -47,20 +46,6 @@ uint8_t oled_get_current_line();
void oled_set_brightness(uint8_t lvl);
/* Print an arrow at given position*/
void oled_print_arrow(uint8_t row, uint8_t col);
/* Print a backarrow at given position*/
void oled_print_backarrow(uint8_t row, uint8_t col);
/* Print Game Over image found in progmem */
void oled_print_game_over();
/* Print the Pong startup image */
void oled_print_pong();
/* Print a pitmap to the screen */
void oled_write_bitmap(const uint8_t* bm);
/************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment