Uploaded project to git
This commit is contained in:
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
===============================================================================
|
||||
Name : labo2 Ecran SPI
|
||||
Author : M-Rohmer
|
||||
Copyright : HES-SO hepia
|
||||
Year : 2024
|
||||
===============================================================================
|
||||
*/
|
||||
|
||||
|
||||
#include "config_LPC1769.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "GPIO.h"
|
||||
#include "SPI.h"
|
||||
|
||||
const Point SCREEN_ORIGIN = {0,0};
|
||||
const Size SCREEN_SIZE = {240,320};
|
||||
const Rectangle SCREEN = {SCREEN_ORIGIN,SCREEN_SIZE};
|
||||
|
||||
void init(void)
|
||||
{
|
||||
ILI9341_Initial();
|
||||
}
|
||||
|
||||
int scrolling = 0;
|
||||
bool need_to_scroll = false;
|
||||
|
||||
void EINT3_IRQHandler(void){
|
||||
int buttonPressed = Detect_AB_buttons();
|
||||
if(buttonPressed == 2){
|
||||
//button A pressed
|
||||
}else{
|
||||
//button B pressed
|
||||
}
|
||||
ClearButtons();
|
||||
}
|
||||
|
||||
int timer_count = 0;
|
||||
int scroller_divider = 25;
|
||||
void SysTick_Handler(){
|
||||
timer_count += 1;
|
||||
|
||||
//update the screen
|
||||
|
||||
if(timer_count >= scroller_divider){
|
||||
increment_scroll(-1);
|
||||
need_to_scroll = true;
|
||||
timer_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void increment_scroll(int value){
|
||||
scrolling += value;
|
||||
if(scrolling <= 0)
|
||||
scrolling = 319;
|
||||
if(scrolling >= 320)
|
||||
scrolling = 1;
|
||||
}
|
||||
|
||||
int number_of_digits (int value){
|
||||
int interVal = value;
|
||||
int count = 0;
|
||||
while(interVal > 0){
|
||||
interVal = interVal /10;
|
||||
count ++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void convert_to_string(int value, int nbr_digits, char* str){
|
||||
for(int i = nbr_digits-1; i >= 0; i--){
|
||||
int interVal = value;
|
||||
interVal /= 10;
|
||||
int res = value - interVal * 10;
|
||||
str[i] = '0'+res;
|
||||
value /= 10;
|
||||
}
|
||||
str[nbr_digits] = '\0';
|
||||
}
|
||||
|
||||
void scroll_array(int **array,int **newArray,int width,int height){
|
||||
for(int y = 0;y < height;y++){
|
||||
for(int x = 0;x < width;x++){
|
||||
if(y < height-1 && x < width -1)
|
||||
newArray[x+1][y+1] = array[x][y];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
InitButtons();
|
||||
InitTimer();
|
||||
LedSetState8(128+32+8+2);
|
||||
Point text_origin = {240 / 2 - 8/2,(320 / 6) * 5 - 4};
|
||||
|
||||
Resize_Window(SCREEN);
|
||||
Draw_stars();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if(need_to_scroll){
|
||||
scroll(scrolling);
|
||||
need_to_scroll = false;
|
||||
|
||||
int digits = number_of_digits(scrolling);
|
||||
char newStr[digits+1];
|
||||
convert_to_string(scrolling,digits,&newStr);
|
||||
Size charSize = {7,11};
|
||||
Point new_origin = {text_origin.X,(text_origin.Y + scrolling)%320};
|
||||
Rectangle areaToRefresh = {{new_origin.X,new_origin.Y},{charSize.Width* 4,charSize.Height+5}};
|
||||
|
||||
Refresh_Area(areaToRefresh);
|
||||
DrawText(new_origin,newStr,charSize);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user