Commit f0e6d6e3 authored by Pedro Henrique Kopper's avatar Pedro Henrique Kopper

Quebrar o main.c em arquivos menores e adicionar GPLv3

parent f057abdf
This diff is collapsed.
......@@ -124,7 +124,9 @@ CSRC = $(ALLCSRC) \
$(TESTSRC) \
$(CHIBIOS)/os/various/syscalls.c \
./lib/ssd1306.c \
usbcfg.c \
./threads/status.c \
./threads/display.c \
./usb/usbcfg.c \
main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
......@@ -138,7 +140,7 @@ ASMSRC = $(ALLASMSRC)
ASMXSRC = $(ALLXASMSRC)
# Inclusion directories.
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) $(ROOT)/lib
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC) $(ROOT)/lib $(ROOT)/threads
# Define C warning options here.
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
......
# SACADA Mini Firmware template
# SACADA Mini Firmware
This repository contains a template for developing firmware for SACADA Mini boards. It contains everything you need to blink a LED and write stuff to UART. You're expected to bring your own compiler suite (arm-none-eabi-*) and clone this repository along with it submodules:
......@@ -24,4 +24,6 @@ or by shorting JP2 and using DFU (USB):
sudo dfu-util -a 0 -D build/ch.bin -s 0x08000000:leave
```
Copyright 2019 Pedro Henrique Capp Kopper
Enjoy!
\ No newline at end of file
#include "ch.h"
#include "hal.h"
#include "board.h"
#include "rt_test_root.h"
#include "oslib_test_root.h"
#include <stdio.h>
#include "usbcfg.h"
#include "ssd1306.h"
#include "./threads/status.h"
#include "./threads/display.h"
#include "./usb/usbcfg.h"
// Callback placeholders
#define usb_lld_connect_bus(usbp)
#define usb_lld_disconnect_bus(usbp)
static const I2CConfig i2ccfg = {
STM32_TIMINGR_PRESC(8U) | STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
STM32_TIMINGR_SCLH(3U) | STM32_TIMINGR_SCLL(9U),
0,
0
};
static const SSD1306Config ssd1306cfg = {
&I2CD1,
&i2ccfg,
SSD1306_SAD_0X78,
};
static SSD1306Driver SSD1306D1;
static THD_WORKING_AREA(waOledDisplay, 1024);
static THD_FUNCTION(OledDisplay, arg) {
(void)arg;
chRegSetThreadName("OledDisplay");
ssd1306ObjectInit(&SSD1306D1);
ssd1306Start(&SSD1306D1, &ssd1306cfg);
ssd1306ToggleInvert(&SSD1306D1);
ssd1306FillScreen(&SSD1306D1, 0x00);
int i = 0;
while (TRUE) {
ssd1306FillScreen(&SSD1306D1, 0x01);
char buf[32] = {0};
ssd1306GotoXy(&SSD1306D1, 0, 1);
ssd1306Puts(&SSD1306D1, "TESTE", &ssd1306_font_11x18, SSD1306_COLOR_WHITE);
ssd1306GotoXy(&SSD1306D1, 0, 32);
ssd1306Puts(&SSD1306D1, "0123456789", &ssd1306_font_11x18, SSD1306_COLOR_WHITE);
ssd1306UpdateScreen(&SSD1306D1);
i++;
chThdSleepMilliseconds(1000);
}
ssd1306Stop(&SSD1306D1);
}
/*
* Green LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (true) {
palClearLine(LINE_LED0);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED0);
chThdSleepMilliseconds(100);
palClearLine(LINE_LED1);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED1);
chThdSleepMilliseconds(100);
palClearLine(LINE_LED2);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED2);
chThdSleepMilliseconds(100);
}
}
/*
* Application entry point.
*/
......@@ -96,6 +28,9 @@ int main(void) {
palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(14));
palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(14));
/*
* Initializes USB serial interfaces
*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg1);
sduObjectInit(&SDU2);
......@@ -104,30 +39,32 @@ int main(void) {
usbStart(serusbcfg1.usbp, &usbcfg);
usbConnectBus(serusbcfg1.usbp);
/*
* Activates the serial driver 3 using the driver default configuration.
*/
sdStart(&SD3, NULL);
/*
* Creates the blinker thread.
* Configures GPIO
*/
palSetLineMode(LINE_LED0, PAL_MODE_OUTPUT_PUSHPULL);
palSetLineMode(LINE_LED1, PAL_MODE_OUTPUT_PUSHPULL);
palSetLineMode(LINE_LED2, PAL_MODE_OUTPUT_PUSHPULL);
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4));
palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7));
palSetLineMode(LINE_LED0, PAL_MODE_OUTPUT_PUSHPULL); // LED0 output
palSetLineMode(LINE_LED1, PAL_MODE_OUTPUT_PUSHPULL); // LED1 output
palSetLineMode(LINE_LED2, PAL_MODE_OUTPUT_PUSHPULL); // LED2 output
palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4)); // I2C1 SCL
palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4)); // I2C1 SDA
palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7)); // UART3
palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7)); // UART3
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
chThdCreateStatic(waThread1, sizeof(waOledDisplay), NORMALPRIO, OledDisplay, NULL);
/*
* Starts running the threads
*/
chThdCreateStatic(waStatus, sizeof(waStatus), NORMALPRIO, Status, NULL);
chThdCreateStatic(waDisplay, sizeof(waDisplay), NORMALPRIO, Display, NULL);
/*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
* Normal main() thread activity.
* For now it just sleeps in a loop.
*/
while (true) {
chThdSleepMilliseconds(500);
......
#include "ch.h"
#include "hal.h"
#include "board.h"
#include <stdio.h>
#include "ssd1306.h"
/* DISPLAY THREAD
*
* This thread displays debug info on the OLED display.
*/
static const I2CConfig i2ccfg = {
STM32_TIMINGR_PRESC(8U) | STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
STM32_TIMINGR_SCLH(3U) | STM32_TIMINGR_SCLL(9U),
0,
0
};
static const SSD1306Config ssd1306cfg = {
&I2CD1,
&i2ccfg,
SSD1306_SAD_0X78,
};
static SSD1306Driver SSD1306D1;
THD_WORKING_AREA(waDisplay, 512);
THD_FUNCTION(Display, arg) {
(void)arg;
chRegSetThreadName("OledDisplay");
ssd1306ObjectInit(&SSD1306D1);
ssd1306Start(&SSD1306D1, &ssd1306cfg);
ssd1306ToggleInvert(&SSD1306D1);
ssd1306FillScreen(&SSD1306D1, 0x00);
while (TRUE) {
ssd1306FillScreen(&SSD1306D1, 0x01);
ssd1306GotoXy(&SSD1306D1, 0, 1);
ssd1306Puts(&SSD1306D1, "THREAD", &ssd1306_font_11x18, SSD1306_COLOR_WHITE);
ssd1306GotoXy(&SSD1306D1, 0, 32);
ssd1306Puts(&SSD1306D1, "ABC", &ssd1306_font_11x18, SSD1306_COLOR_WHITE);
ssd1306UpdateScreen(&SSD1306D1);
chThdSleepMilliseconds(1000);
}
ssd1306Stop(&SSD1306D1);
}
#ifndef DISPLAY_H
#define DISPLAY_H
extern THD_WORKING_AREA(waDisplay, 512);
THD_FUNCTION(Display, arg);
#endif /* DISPLAY_H */
#include "ch.h"
#include "hal.h"
#include "board.h"
#include "status.h"
/* STATUS THREAD
*
* This thread handles the onboard LEDs and debugging ports
*/
#define DEBUG &SD3 // UART3
THD_WORKING_AREA(waStatus, 128);
THD_FUNCTION(Status, arg) {
(void)arg;
chRegSetThreadName("status");
// Just blinks in sequence to test onboard LEDs
while (true) {
palClearLine(LINE_LED0);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED0);
chThdSleepMilliseconds(100);
palClearLine(LINE_LED1);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED1);
chThdSleepMilliseconds(100);
palClearLine(LINE_LED2);
chThdSleepMilliseconds(100);
palSetLine(LINE_LED2);
chThdSleepMilliseconds(100);
sdWrite(DEBUG, (uint8_t *)"Teste\r\n", sizeof("Teste\r\n"));
}
}
\ No newline at end of file
#ifndef STATUS_H
#define STATUS_H
extern THD_WORKING_AREA(waStatus, 128);
THD_FUNCTION(Status, arg);
#endif /* STATUS_H */
......@@ -208,34 +208,34 @@ static const uint8_t vcom_string0[] = {
* Vendor string.
*/
static const uint8_t vcom_string1[] = {
USB_DESC_BYTE(38), /* bLength. */
USB_DESC_BYTE(48), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0,
'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0,
'c', 0, 's', 0
'b', 0, 'l', 0, 'a', 0, 'z', 0, 'i', 0, 'n', 0, 'g', 0, '.', 0, 'd', 0, 'e', 0, 's', 0, 'i', 0, 'g', 0, 'n', 0, '/', 0, 'I', 0, 'F', 0, '-', 0, 'U', 0, 'F', 0, 'R', 0, 'G', 0, 'S', 0,
};
/*
* Device Description string.
*/
static const uint8_t vcom_string2[] = {
USB_DESC_BYTE(56), /* bLength. */
USB_DESC_BYTE(24), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'C', 0, 'h', 0, 'i', 0, 'b', 0, 'i', 0, 'O', 0, 'S', 0, '/', 0,
'R', 0, 'T', 0, ' ', 0, 'V', 0, 'i', 0, 'r', 0, 't', 0, 'u', 0,
'a', 0, 'l', 0, ' ', 0, 'C', 0, 'O', 0, 'M', 0, ' ', 0, 'P', 0,
'o', 0, 'r', 0, 't', 0
'S', 0, 'A', 0, 'C', 0, 'A', 0, 'D', 0, 'A', 0, ' ', 0, 'M', 0, 'i', 0, 'n', 0, 'i', 0,
};
/*
* Serial Number string.
*/
static const uint8_t vcom_string3[] = {
USB_DESC_BYTE(8), /* bLength. */
USB_DESC_BYTE(18), /* bLength. */
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
'0' + CH_KERNEL_MAJOR, 0,
'0' + CH_KERNEL_MINOR, 0,
'0' + CH_KERNEL_PATCH, 0
'0', 0,
'0', 0,
'0', 0,
'0', 0,
'0', 0,
'0', 0,
'0', 0,
'1', 0
};
/*
......
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