Skip to content

Commit a09b557

Browse files
committed
Initial commit
0 parents  commit a09b557

27 files changed

+3267
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 项目排除路径
2+
/cmake-build-debug/

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deployment.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/eetree-esp32.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
set(IDF_TARGET esp32s2)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(smart_config)

Hardwares/OLED/oled.c

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#include <driver/spi_master.h>
2+
#include <freertos/task.h>
3+
#include "oled.h"
4+
#include "oledfont.h"
5+
#include "driver/spi_common.h"
6+
#include "driver/gpio.h"
7+
#include "main.h"
8+
9+
uint8_t **Hzk;
10+
11+
spi_device_handle_t oled_spi_handle;
12+
13+
void oled_send(uint8_t dc, uint8_t data) {
14+
spi_transaction_t t = {0};
15+
t.length = 8;
16+
t.tx_buffer = &data;
17+
gpio_set_level(OLED_DC_Pin, dc == 0x40);
18+
spi_device_polling_transmit(oled_spi_handle, &t);
19+
}
20+
21+
/// OLED init commands
22+
uint8_t CMD_Data[] = {
23+
0xAE, 0x00, 0x10, 0x40, 0xB0, 0x81, 0xFF, 0xA1, 0xA6, 0xA8, 0x3F,
24+
0xC8, 0xD3, 0x00, 0xD5, 0x80, 0xD8, 0x05, 0xD9, 0xF1, 0xDA, 0x12,
25+
0xD8, 0x30, 0x8D, 0x14, 0xAF};
26+
27+
void OLED_WR_CMD(uint8_t cmd) {
28+
oled_send(0x00, cmd);
29+
}
30+
31+
void OLED_WR_DATA(uint8_t data) {
32+
oled_send(0x40, data);
33+
}
34+
35+
void OLED_Init(void) {
36+
gpio_set_level(OLED_RST_Pin, 0);
37+
vTaskDelay(100 / portTICK_RATE_MS);
38+
gpio_set_level(OLED_RST_Pin, 1);
39+
vTaskDelay(100 / portTICK_RATE_MS);
40+
uint8_t i = 0;
41+
for (i = 0; i < 27; i++) {
42+
oled_send(0x00, CMD_Data[i]);
43+
}
44+
}
45+
46+
void OLED_Clear() {
47+
uint8_t i, n;
48+
for (i = 0; i < 8; i++) {
49+
OLED_WR_CMD(0xb0 + i);
50+
OLED_WR_CMD(0x00);
51+
OLED_WR_CMD(0x10);
52+
for (n = 0; n < 128; n++)
53+
OLED_WR_DATA(0);
54+
}
55+
}
56+
57+
void OLED_Display_On(void) {
58+
OLED_WR_CMD(0X8D); //SET DCDC命令
59+
OLED_WR_CMD(0X14); //DCDC ON
60+
OLED_WR_CMD(0XAF); //DISPLAY ON
61+
}
62+
63+
void OLED_Display_Off(void) {
64+
OLED_WR_CMD(0X8D); //SET DCDC命令
65+
OLED_WR_CMD(0X10); //DCDC OFF
66+
OLED_WR_CMD(0XAE); //DISPLAY OFF
67+
}
68+
69+
void OLED_Set_Pos(uint8_t x, uint8_t y) {
70+
OLED_WR_CMD(0xb0 + y);
71+
OLED_WR_CMD(((x & 0xf0) >> 4) | 0x10);
72+
OLED_WR_CMD(x & 0x0f);
73+
}
74+
75+
void OLED_On(void) {
76+
uint8_t i, n;
77+
for (i = 0; i < 8; i++) {
78+
OLED_WR_CMD(0xb0 + i); //设置页地址(0~7)
79+
OLED_WR_CMD(0x00); //设置显示位置—列低地址
80+
OLED_WR_CMD(0x10); //设置显示位置—列高地址
81+
for (n = 0; n < 128; n++)
82+
OLED_WR_DATA(1);
83+
} //更新显示
84+
}
85+
86+
unsigned int oled_pow(uint8_t m, uint8_t n) {
87+
unsigned int result = 1;
88+
while (n--)result *= m;
89+
return result;
90+
}
91+
92+
void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr, uint8_t Char_Size) {
93+
unsigned char c = 0, i = 0;
94+
c = chr - ' ';//得到偏移后的值
95+
if (x > 128 - 1) {
96+
x = 0;
97+
y = y + 2;
98+
}
99+
if (Char_Size == 16) {
100+
OLED_Set_Pos(x, y);
101+
for (i = 0; i < 8; i++)
102+
OLED_WR_DATA(F8x16[c * 16 + i]);
103+
OLED_Set_Pos(x, y + 1);
104+
for (i = 0; i < 8; i++)
105+
OLED_WR_DATA(F8x16[c * 16 + i + 8]);
106+
} else {
107+
OLED_Set_Pos(x, y);
108+
for (i = 0; i < 6; i++)
109+
OLED_WR_DATA(F6x8[c][i]);
110+
111+
}
112+
}
113+
114+
void OLED_ShowString(uint8_t x, uint8_t y, uint8_t *chr, uint8_t Char_Size) {
115+
unsigned char j = 0;
116+
while (chr[j] != '\0') {
117+
OLED_ShowChar(x, y, chr[j], Char_Size);
118+
x += 8;
119+
if (x > 120) {
120+
x = 0;
121+
y += 2;
122+
}
123+
j++;
124+
}
125+
}
126+
127+
void OLED_ShowNum(uint8_t x, uint8_t y, int32_t num, uint8_t Char_Size) {
128+
uint32_t j = 1;
129+
if (num < 0) {
130+
OLED_ShowChar(x, y, '-', Char_Size);
131+
x += 8;
132+
if (x > 120) {
133+
x = 0;
134+
y += 2;
135+
}
136+
num = -num;
137+
}
138+
while (j <= num) {
139+
j *= 10;
140+
}
141+
j /= 10;
142+
while (j > 1) {
143+
OLED_ShowChar(x, y, num / j + '0', Char_Size);
144+
x += 8;
145+
if (x > 120) {
146+
x = 0;
147+
y += 2;
148+
}
149+
num %= j;
150+
j /= 10;
151+
}
152+
OLED_ShowChar(x, y, num + '0', Char_Size);
153+
}
154+
155+
void OLED_ShowCHinese(uint8_t x, uint8_t y, uint8_t no) {
156+
uint8_t t, adder = 0;
157+
OLED_Set_Pos(x, y);
158+
for (t = 0; t < 16; t++) {
159+
OLED_WR_DATA(Hzk[2 * no][t]);
160+
adder += 1;
161+
}
162+
OLED_Set_Pos(x, y + 1);
163+
for (t = 0; t < 16; t++) {
164+
OLED_WR_DATA(Hzk[2 * no + 1][t]);
165+
adder += 1;
166+
}
167+
}

Hardwares/OLED/oled.h

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef __OLED_H_
2+
#define __OLED_H_
3+
4+
#include "stdint.h"
5+
#include "driver/spi_master.h"
6+
7+
extern spi_device_handle_t oled_spi_handle;
8+
9+
/// the i2c address of the oled
10+
#define OLED_ADDR 0x78
11+
12+
/**
13+
* @brief Construct a new oled send object
14+
*
15+
* @param dc the control command or the data order
16+
* @param data
17+
*/
18+
void oled_send(uint8_t dc, uint8_t data);
19+
20+
/**
21+
* @brief write the control cammand to the oled
22+
*
23+
* @param cmd
24+
*/
25+
void OLED_WR_CMD(uint8_t cmd);
26+
27+
/**
28+
* @brief write the data to the oled
29+
*
30+
* @param data
31+
*/
32+
void OLED_WR_DATA(uint8_t data);
33+
34+
/**
35+
* @brief init the OLED
36+
*
37+
*/
38+
void OLED_Init(void);
39+
40+
/**
41+
* @brief clear the oled screen
42+
*
43+
*/
44+
void OLED_Clear(void);
45+
46+
/**
47+
* @brief turn on the display
48+
*
49+
*/
50+
void OLED_Display_On(void);
51+
52+
/**
53+
* @brief turn off the display
54+
*
55+
*/
56+
void OLED_Display_Off(void);
57+
58+
void OLED_Set_Pos(uint8_t x, uint8_t y);
59+
60+
void OLED_On(void);
61+
62+
/**
63+
* @brief display a character at the place on the OLED.
64+
*
65+
* @param x the abscissa of the character. Should between 0 and 127.
66+
* @param y the ordinate of the character. Should between 0 and 7.
67+
* @param chr the character
68+
* @param Char_Size the size of the character. Should be 16 or 12.
69+
*/
70+
void OLED_ShowChar(uint8_t x,uint8_t y,uint8_t chr,uint8_t Char_Size);
71+
72+
/**
73+
* @brief display a string at the place on the OLED.
74+
*
75+
* @param x the abscissa of the character. Should between 0 and 127.
76+
* @param y the ordinate of the character. Should between 0 and 7.
77+
* @param chr the pointer of the char array
78+
* @param Char_Size the size of the character. Should be 16 or 12.
79+
*/
80+
void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size);
81+
82+
void OLED_ShowNum(uint8_t x, uint8_t y, int32_t num, uint8_t Char_Size);
83+
84+
/**
85+
* @brief display a Chinese character at the place on the OLED.
86+
* the Chinese character should be build by a character matrix software
87+
* like PCtoLCD. and it should be stored in the hzk array.
88+
*
89+
* @param x the abscissa of the character. Should between 0 and 127.
90+
* @param y the ordinate of the character. Should between 0 and 7.
91+
* @param no the first coordinate of the Chinese character in hzk.
92+
*/
93+
void OLED_ShowCHinese(uint8_t x,uint8_t y,uint8_t no);
94+
95+
#endif

0 commit comments

Comments
 (0)