Commit c90a1ef2 authored by Mikaël BRIDAY's avatar Mikaël BRIDAY

dummy serial for lab5

parent 1bc6b2ae
......@@ -11,8 +11,8 @@ project(lab5)
#application sources
set(SRCS
${CMAKE_SOURCE_DIR}/main.cpp
${CMAKE_SOURCE_DIR}/main.c
)
option(WITH_TFT "add compilation rules for the TFT support" ON)
#option(WITH_TFT "add compilation rules for the TFT support" ON)
include("../sys/cmake/coroLabs.cmake")
#include "stm32f3xx.h"
#include "dummySerial.h"
void wait()
{
volatile int i=0;
for(i=0;i<200000;i++);
}
void setup()
{
RCC->AHBENR |= RCC_AHBENR_GPIOBEN_Msk; //clock for GPIOB
__asm("nop"); //wait until GPIOB clock is Ok.
GPIOB->MODER = 1 << (3*2); //PB3 output
}
/* main function */
int main(void)
{
setup();
serialPutString("coucou!\n");
/* Infinite loop */
while (1)
{
/* Add application code here */
GPIOB->BSRR = 1<<3; //bit set
wait();
GPIOB->BSRR = 1<<(3+16); //bit reset
wait();
}
}
#include "stm32f3xx.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ST7735.h"
#include "adc.h"
#include "tft.h"
void setup()
{
Tft.setup();
Tft.setTextCursor(4, 1); //col,line
Tft.print("Hello World! ");
ADCInit();
}
//this is a simple application that uses the TFT display.
// => it first write a string in the top of the screen (in setup)
// => it writes the ADC value of the potentiometer in green, and
// refreshes it each time the value differs more than 5.
int main()
{
static int prevPot = -1;
setup();
while(1)
{
//potentiometer
int pot = ADCRead(); //12 bits -> 4096 -> 4 digits
//update only we value changes significantly
if(abs(prevPot - pot) > 5)
{
//set cursor centered on line 4.
Tft.setTextCursor(Tft.getTextWidth()/2-2,4);
Tft.eraseText(4); //remove previous value (4 digits)
Tft.print(pot);
prevPot = pot;
}
}
}
#include "adc.h"
#include "stm32f3xx.h"
void serialInit()
{
}
void serialPutChar(char c)
{
USART2->TDR = c;
}
void serialPutString(char *c)
{
while(*c) serialPutChar(*c++);
}
#ifndef __DUMMY_SERIAL_H__
#define __DUMMY_SERIAL_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** serial line init */
void serialInit();
/** send one ASCII char on the serial line. */
void serialPutChar(char c);
/** send a NULL terminate ASCII string on the serial line. */
void serialPutString(char *c);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
......@@ -39,6 +39,7 @@ set(LIBSRCS
${LIB_DIR}/adc.c
${LIB_DIR}/pinAccess.c
${LIB_DIR}/spi.c
${LIB_DIR}/dummySerial.c
)
set(APP_SRCS ${SRCS} ${LIBSRCS} ${TFT_SRCS})
......
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