mirror of
https://gitee.com/peng_zhihui/HoloCubic
synced 2025-11-04 21:19:40 +08:00
[Fw] Add firmware files.
This commit is contained in:
parent
7b861ebd62
commit
0003de5845
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,4 +5,5 @@
|
|||||||
1.Hardware/HoloCubic-Assembled/ExtendBoard/ExtendBoard.PrjPCBStructure
|
1.Hardware/HoloCubic-Assembled/ExtendBoard/ExtendBoard.PrjPCBStructure
|
||||||
1.Hardware/HoloCubic-Assembled/MainBoard/History
|
1.Hardware/HoloCubic-Assembled/MainBoard/History
|
||||||
1.Hardware/HoloCubic-Assembled/MainBoard/MainBoard.PrjPCBStructure
|
1.Hardware/HoloCubic-Assembled/MainBoard/MainBoard.PrjPCBStructure
|
||||||
1.Hardware/HoloCubic-Assembled/MainBoard/Project Outputs for MainBoard
|
1.Hardware/HoloCubic-Assembled/MainBoard/Project Outputs for MainBoard
|
||||||
|
2.Firmware/HoloCubic_fw/.vs
|
||||||
|
|||||||
33
2.Firmware/HoloCubic_fw/HoloCubic_fw.ino
Normal file
33
2.Firmware/HoloCubic_fw/HoloCubic_fw.ino
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "display.h"
|
||||||
|
#include "imu.h"
|
||||||
|
#include <lv_examples/lv_examples.h>
|
||||||
|
|
||||||
|
Display screen;
|
||||||
|
|
||||||
|
// MPU6050 accelerator and gyroscope
|
||||||
|
IMU mpu;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
screen.init();
|
||||||
|
screen.setBackLight(0.2);
|
||||||
|
|
||||||
|
mpu.init();
|
||||||
|
|
||||||
|
|
||||||
|
lv_demo_benchmark();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// run this as often as possible ¡ý
|
||||||
|
screen.runtime();
|
||||||
|
|
||||||
|
mpu.update();
|
||||||
|
|
||||||
|
|
||||||
|
delay(5);
|
||||||
|
}
|
||||||
67
2.Firmware/HoloCubic_fw/display.cpp
Normal file
67
2.Firmware/HoloCubic_fw/display.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "display.h"
|
||||||
|
#include <TFT_eSPI.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
TFT pins should be set in path/to/Arduino/libraries/TFT_eSPI/User_Setups/Setup24_ST7789.h
|
||||||
|
*/
|
||||||
|
TFT_eSPI tft = TFT_eSPI();
|
||||||
|
|
||||||
|
static lv_disp_buf_t disp_buf;
|
||||||
|
static lv_color_t buf[LV_HOR_RES_MAX * 10];
|
||||||
|
|
||||||
|
void my_print(lv_log_level_t level, const char* file, uint32_t line, const char* fun, const char* dsc)
|
||||||
|
{
|
||||||
|
Serial.printf("%s@%d %s->%s\r\n", file, line, fun, dsc);
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void my_disp_flush(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p)
|
||||||
|
{
|
||||||
|
uint32_t w = (area->x2 - area->x1 + 1);
|
||||||
|
uint32_t h = (area->y2 - area->y1 + 1);
|
||||||
|
|
||||||
|
tft.startWrite();
|
||||||
|
tft.setAddrWindow(area->x1, area->y1, w, h);
|
||||||
|
tft.pushColors(&color_p->full, w * h, true);
|
||||||
|
tft.endWrite();
|
||||||
|
|
||||||
|
lv_disp_flush_ready(disp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Display::init()
|
||||||
|
{
|
||||||
|
ledcSetup(LCD_BL_PWM_CHANNEL, 5000, 8);
|
||||||
|
ledcAttachPin(LCD_BL_PIN, LCD_BL_PWM_CHANNEL);
|
||||||
|
|
||||||
|
lv_init();
|
||||||
|
|
||||||
|
lv_log_register_print_cb(my_print); /* register print function for debugging */
|
||||||
|
|
||||||
|
tft.begin(); /* TFT init */
|
||||||
|
tft.setRotation(4); /* mirror */
|
||||||
|
|
||||||
|
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
|
||||||
|
|
||||||
|
/*Initialize the display*/
|
||||||
|
lv_disp_drv_t disp_drv;
|
||||||
|
lv_disp_drv_init(&disp_drv);
|
||||||
|
disp_drv.hor_res = 240;
|
||||||
|
disp_drv.ver_res = 240;
|
||||||
|
disp_drv.flush_cb = my_disp_flush;
|
||||||
|
disp_drv.buffer = &disp_buf;
|
||||||
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::runtime()
|
||||||
|
{
|
||||||
|
lv_task_handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::setBackLight(float duty)
|
||||||
|
{
|
||||||
|
duty = constrain(duty, 0, 1);
|
||||||
|
duty = 1 - duty;
|
||||||
|
ledcWrite(LCD_BL_PWM_CHANNEL, (int)(duty * 255));
|
||||||
|
}
|
||||||
16
2.Firmware/HoloCubic_fw/display.h
Normal file
16
2.Firmware/HoloCubic_fw/display.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
#define LCD_BL_PIN 5
|
||||||
|
#define LCD_BL_PWM_CHANNEL 0
|
||||||
|
|
||||||
|
|
||||||
|
class Display
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init();
|
||||||
|
void runtime();
|
||||||
|
void setBackLight(float);
|
||||||
|
};
|
||||||
45
2.Firmware/HoloCubic_fw/imu.cpp
Normal file
45
2.Firmware/HoloCubic_fw/imu.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "imu.h"
|
||||||
|
|
||||||
|
|
||||||
|
void IMU::init()
|
||||||
|
{
|
||||||
|
Wire.begin(IMU_I2C_SDA, IMU_I2C_SCL);
|
||||||
|
Wire.setClock(400000);
|
||||||
|
while (!imu.testConnection());
|
||||||
|
imu.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMU::update()
|
||||||
|
{
|
||||||
|
imu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getAccelX()
|
||||||
|
{
|
||||||
|
return ax;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getAccelY()
|
||||||
|
{
|
||||||
|
return ay;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getAccelZ()
|
||||||
|
{
|
||||||
|
return az;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getGyroX()
|
||||||
|
{
|
||||||
|
return gx;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getGyroY()
|
||||||
|
{
|
||||||
|
return gy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t IMU::getGyroZ()
|
||||||
|
{
|
||||||
|
return gz;
|
||||||
|
}
|
||||||
27
2.Firmware/HoloCubic_fw/imu.h
Normal file
27
2.Firmware/HoloCubic_fw/imu.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <I2Cdev.h>
|
||||||
|
#include <MPU6050.h>
|
||||||
|
|
||||||
|
#define IMU_I2C_SDA 32
|
||||||
|
#define IMU_I2C_SCL 33
|
||||||
|
|
||||||
|
class IMU
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
MPU6050 imu;
|
||||||
|
int16_t ax, ay, az;
|
||||||
|
int16_t gx, gy, gz;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
int16_t getAccelX();
|
||||||
|
int16_t getAccelY();
|
||||||
|
int16_t getAccelZ();
|
||||||
|
|
||||||
|
int16_t getGyroX();
|
||||||
|
int16_t getGyroY();
|
||||||
|
int16_t getGyroZ();
|
||||||
|
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user