#include "usbd_conf.h"
#include "usbd_core.h"
#include "usbd_hid.h"
#include "usbd_desc.h"
USBD_HandleTypeDef usb;
uint16_t countNoInit __attribute__((section(".noinit")));
static void taskAdc(void *) {
Serial.printf(
"A0:%5d mV, ",
map(analogRead(A0), 0, 4095, 0, 3300));
Serial.printf(
"A1:%5d mV, ",
map(analogRead(A1), 0, 4095, 0, 3300));
Serial.printf(
"A2:%5d mV, ",
map(analogRead(A2), 0, 4095, 0, 3300));
Serial.printf(
"A3:%5d mV, ",
map(analogRead(A3), 0, 4095, 0, 3300));
Serial.printf(
"A4:%5d mV, ",
map(analogRead(A4), 0, 4095, 0, 3300));
Serial.printf(
"A5:%5d mV, ",
map(analogRead(A5), 0, 4095, 0, 3300));
Serial.printf(
"A6:%5d mV, ",
map(analogRead(A6), 0, 4095, 0, 3300));
Serial.printf(
"A7:%5d mV, ",
map(analogRead(A7), 0, 4095, 0, 3300));
Serial.printf(
"A8:%5d mV\n",
map(analogRead(A8), 0, 4095, 0, 3300));
}
}
}
static void eventUserKeyPressed() {
static int8_t cnt = 0;
int8_t x = 0, y = 0;
if (cnt++ > 0) {
x = 5;
} else {
x = -5;
}
uint8_t buf[4];
buf[0] = 0;
buf[1] = x;
buf[2] = y;
buf[3] = 0;
USBD_HID_SendReport(&usb, buf, 4);
Serial.println("* User key is pressed.");
}
static void taskHello(void *) {
struct timeval t;
gettimeofday(&t, NULL);
Serial.printf("[%lu.%06lu] (Serial) Hello World! count:%u\n", (uint32_t) t.tv_sec, t.tv_usec, countNoInit);
Serial2.printf(
"[%lu.%06lu] (Serial2) Hello World! count:%u\n", (uint32_t) t.tv_sec, t.tv_usec, countNoInit);
countNoInit++;
}
void setup() {
Serial.begin(115200);
Serial.println("*** [ST Nucleo-F429ZI] Basic Functions ***");
Serial.onReceive(eventSerialRx);
#ifndef MEASURE_CURRENT_IN_SLEEP
Serial.listen();
#endif
Serial2.println(
"*** [ST Nucleo-F429ZI] Basic Functions ***");
#ifndef MEASURE_CURRENT_IN_SLEEP
#endif
USBD_StatusTypeDef s;
if ((s = USBD_Init(&usb, &hid, 0)) != USBD_OK) {
Serial.printf("* USBD_Init() failed: %d\n", s);
return;
}
if ((s = USBD_RegisterClass(&usb, USBD_HID_CLASS)) != USBD_OK) {
Serial.printf("* USBD_RegisterClass() failed: %d\n", s);
return;
}
if ((s = USBD_Start(&usb)) != USBD_OK) {
Serial.printf("* USBD_Start() failed: %d\n", s);
return;
}
attachInterrupt(PC13, eventUserKeyPressed, RISING);
timerHello.
onFired(taskHello, NULL);
}
시리얼 포트를 제어하기 위한 클래스
Definition SerialPort.hpp:76
virtual size_t write(uint8_t val)
문자 하나를 출력합니다.
virtual int read()
포트 내부 버퍼에 수신된 문자를 하다 꺼냅니다.
virtual int available()
포트 내부 수신버퍼에 수신된 문자의 갯수를 반환합니다.
Timer는 일정 시간 이후에 1회 실행될 작업, 매 일정 시간마다 실행될 작업 등을 위한 기능입니다.
Definition Timer.hpp:61
bool startPeriodic(uint32_t millis, bool interrupt=false)
작업함수를 매 millis 밀리초 주기로 반복하여 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
long map(long x, long in_min, long in_max, long out_min, long out_max)
수를 어떤 범위에서 다른 범위로 매핑시킵니다.
bool digitalWrite(int8_t pin, int value)
pin 를 HIGH 또는 LOW 로 설정합니다.
bool pinMode(int8_t pin, enum ioDirection direction)
pin 을 direction 방향을 갖는 디지털 핀으로 동작하도록 설정합니다.
bool digitalToggle(int8_t pin)
pin 을 토글합니다.
@ OUTPUT
Definition nola-common.h:383
@ INPUT
Definition nola-common.h:382