Compare commits
13 Commits
47f14990d5
...
841e30913e
| Author | SHA1 | Date | |
|---|---|---|---|
| 841e30913e | |||
| b1f7e448ab | |||
| 44e4ff3d24 | |||
| 179778d4ac | |||
| e67c12358f | |||
| 363c9568a7 | |||
| c8dc4e7962 | |||
| 1b83af44e9 | |||
| d0b533daf9 | |||
| a2ded46eb3 | |||
| e01ec3e367 | |||
| 55f54a2d4a | |||
| 2663ee6e2a |
27
.vscode/c_cpp_properties.json
vendored
Normal file
27
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/utility/unity/core",
|
||||
"${workspaceFolder}/utility/unity/fixture",
|
||||
"${workspaceFolder}/utility/fff",
|
||||
"${workspaceFolder}/test/cmd_parser/helpers/inc",
|
||||
"${workspaceFolder}/cmd_parser",
|
||||
"${workspaceFolder}/test/oled/helpers/inc",
|
||||
"${workspaceFolder}/oled"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"TEST"
|
||||
],
|
||||
"compilerPath": "C:\\Apps\\mingw64\\bin\\gcc.exe",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "windows-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Unity Test Explorer Debug",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/${command:unityExplorer.debugTestExecutable}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "C:/Apps/mingw64/bin/gdb.exe",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
17
.vscode/settings.json
vendored
Normal file
17
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"unityExplorer.testSourceFileRegex": "\\w+_test.c",
|
||||
"unityExplorer.testCaseRegex": "void\\s+(test_.*)\\s*\\(.*\\)",
|
||||
"unityExplorer.testExecutableRegex": "build/exe/$1.exe",
|
||||
"unityExplorer.testSourceFolder": "test",
|
||||
"unityExplorer.testBuildApplication": "ninja",
|
||||
"unityExplorer.testBuildCwdPath": "build",
|
||||
// "unityExplorer.unitUnderTestFolder": "cmd_parser",
|
||||
"unityExplorer.unitUnderTestFileRegex": "\\w+\\.[ch]",
|
||||
"unityExplorer.prettyTestCaseRegex": "test_(\\w+)",
|
||||
"unityExplorer.prettyTestFileRegex": "(\\w+)_test\\.c",
|
||||
"unityExplorer.debugConfiguration": "Unity Test Explorer Debug",
|
||||
"files.associations": {
|
||||
"main.h": "c"
|
||||
},
|
||||
|
||||
}
|
||||
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "build",
|
||||
"command": "C:/Apps/mingw64/bin/ninja.exe",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -15,4 +15,5 @@ add_definitions(${GLOBAL_DEFINITION})
|
||||
add_subdirectory(utility/unity unity)
|
||||
link_libraries(unity)
|
||||
|
||||
add_subdirectory(test/oled oled)
|
||||
add_subdirectory(test/oled oled)
|
||||
add_subdirectory(test/cmd_parser cmd_parser)
|
||||
89
cmd_parser/cmd_parser.c
Normal file
89
cmd_parser/cmd_parser.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "string.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#include "cmd_parser.h"
|
||||
|
||||
static const cmd_t **cmd_array;
|
||||
static uint8_t cmd_array_size;
|
||||
|
||||
void cmd_parser_init(const cmd_t *commands[], uint8_t size)
|
||||
{
|
||||
cmd_array = commands;
|
||||
cmd_array_size = size;
|
||||
}
|
||||
|
||||
void msg_parse(char *msg)
|
||||
{
|
||||
char *msgptr, *submsgptr;
|
||||
parser_t parser = NULL;
|
||||
result_t result = CMD_OK;
|
||||
char key = 0;
|
||||
|
||||
char *token = strtok_r(msg, " ", &msgptr);
|
||||
if (token[0] == '?')
|
||||
{
|
||||
// help message
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < cmd_array_size; i++)
|
||||
{
|
||||
if (strcmp(token, cmd_array[i]->name) == 0)
|
||||
{
|
||||
parser = cmd_array[i]->parser;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (parser == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (token = strtok_r(NULL, " ", &msgptr); token != NULL; token = strtok_r(NULL, " ", &msgptr))
|
||||
{
|
||||
if (token[0] == '-')
|
||||
{
|
||||
key = token[1];
|
||||
result = parser(key, NULL);
|
||||
if (strlen(token) > 2)
|
||||
{
|
||||
token = token + 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (token[0] != '-')
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case CMD_VALUE_REQ:
|
||||
result = parser(key, token);
|
||||
break;
|
||||
case CMD_MULTIVAL_REQ:
|
||||
for (char *subtoken = strtok_r(token, ", ", &submsgptr); subtoken != NULL; subtoken = strtok_r(NULL, ",", &submsgptr))
|
||||
{
|
||||
if (parser(key, subtoken) == CMD_UNKNOWN)
|
||||
{
|
||||
result = parser(CMDP_KEY_ARG, subtoken);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result = parser(CMDP_KEY_ARG, token);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == CMD_UNKNOWN)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result != CMD_UNKNOWN)
|
||||
{
|
||||
parser(CMDP_KEY_DONE, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser(CMDP_KEY_STOP, NULL);
|
||||
}
|
||||
}
|
||||
24
cmd_parser/cmd_parser.h
Normal file
24
cmd_parser/cmd_parser.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#define CMDP_KEY_DONE 1
|
||||
#define CMDP_KEY_ARG 2
|
||||
#define CMDP_KEY_STOP 3
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CMD_OK,
|
||||
CMD_VALUE_REQ,
|
||||
CMD_MULTIVAL_REQ,
|
||||
CMD_UNKNOWN,
|
||||
} result_t;
|
||||
|
||||
typedef result_t (*parser_t)(char key, char *arg);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
parser_t parser;
|
||||
} cmd_t;
|
||||
|
||||
void cmd_parser_init(const cmd_t *commands[], uint8_t size);
|
||||
void msg_parse(char *msg);
|
||||
59
cmd_parser/cmd_parser2.h
Normal file
59
cmd_parser/cmd_parser2.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
|
||||
#define CMDP_KEY_ARG 1
|
||||
|
||||
typedef void (*help_filter)(char key, const char *text);
|
||||
// key = opt_id, arg = value or NULL
|
||||
// key = CMDP_KEY_ARG, arg = id_arg or token
|
||||
typedef enum
|
||||
{
|
||||
CMD_NULL,
|
||||
CMD_OK,
|
||||
CMD_VALUE_REQ,
|
||||
CMD_MULTIVAL_REQ,
|
||||
CMD_UNKNOWN,
|
||||
} result_t;
|
||||
|
||||
typedef result_t (*parser)(char key, char *arg);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NO_VALUE = 0,
|
||||
SINGLE_VALE = 1,
|
||||
MULTI_VALUE = 2,
|
||||
NOT_OPTIONAL = 4,
|
||||
} option_flags_t;
|
||||
|
||||
typedef const struct
|
||||
{
|
||||
uint8_t opt_id;
|
||||
char *name;
|
||||
char *description;
|
||||
option_flags_t flags;
|
||||
} option_t;
|
||||
|
||||
typedef const struct
|
||||
{
|
||||
char *name;
|
||||
uint8_t arg_id;
|
||||
char *description;
|
||||
option_t *options;
|
||||
uint8_t opt_num;
|
||||
// parser arg_parser;
|
||||
} argument_t;
|
||||
|
||||
typedef const struct
|
||||
{
|
||||
char *name;
|
||||
char *description;
|
||||
argument_t *arguments;
|
||||
uint8_t arg_num;
|
||||
option_t *options;
|
||||
uint8_t opt_num;
|
||||
parser cmd_parser;
|
||||
} cmd_parser_t;
|
||||
|
||||
void cmd_parser_init(cmd_parser_t* commands[], uint8_t size);
|
||||
// void cmd_parse(char *msg, parser parser);
|
||||
void cmd_parse(char *msg);
|
||||
12
oled/connection.c
Normal file
12
oled/connection.c
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
HAL_StatusTypeDef oled_SendCommand(OLED_HandleTypeDef *hOled, uint8_t *pData, uint16_t Size)
|
||||
{
|
||||
return HAL_I2C_Mem_Write(hOled->hi2c, (hOled->DevAddress) << 1, I2C_COMMAND, 1, pData, Size, I2C_TIMEOUT);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef oled_SendData(OLED_HandleTypeDef *hOled, uint8_t *pData, uint16_t Size)
|
||||
{
|
||||
return HAL_I2C_Mem_Write(hOled->hi2c, (hOled->DevAddress) << 1, I2C_DATA, 1, pData, Size, I2C_TIMEOUT);
|
||||
}
|
||||
7
oled/connection.h
Normal file
7
oled/connection.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
#include "oled.h"
|
||||
|
||||
HAL_StatusTypeDef oled_SendCommand(OLED_HandleTypeDef *hOled, uint8_t *pData, uint16_t Size);
|
||||
HAL_StatusTypeDef oled_SendData(OLED_HandleTypeDef *hOled, uint8_t *pData, uint16_t Size);
|
||||
364
oled/gfx.c
Normal file
364
oled/gfx.c
Normal file
@@ -0,0 +1,364 @@
|
||||
#include "gfx.h"
|
||||
|
||||
/**
|
||||
* @brief Set the pixel
|
||||
*
|
||||
* @param hOled Display object
|
||||
* @param x X coordinate
|
||||
* @param y Y coordinate
|
||||
* @param color Color of pixel WHITE(0), BLACK(1) or INVERSE(2)
|
||||
*/
|
||||
void writePixel(OLED_HandleTypeDef *hOled, uint8_t x, uint8_t y, GFX_Color_t color)
|
||||
{
|
||||
if (x > hOled->Width || y > hOled->Height)
|
||||
return;
|
||||
|
||||
switch (color)
|
||||
{
|
||||
case WHITE:
|
||||
hOled->Buffer[(y / 8) * hOled->Width + x] |= (1 << (y % 8));
|
||||
break;
|
||||
case BLACK:
|
||||
hOled->Buffer[(y / 8) * hOled->Width + x] &= ~(1 << (y % 8));
|
||||
break;
|
||||
case INVERSE:
|
||||
hOled->Buffer[(y / 8) * hOled->Width + x] ^= (1 << (y % 8));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t bitmap_max_idx;
|
||||
uint8_t buf_row_first;
|
||||
uint8_t buf_row_last;
|
||||
uint8_t buf_col_first;
|
||||
uint8_t buf_col_last;
|
||||
uint8_t buf_mask_top;
|
||||
uint8_t buf_mask_bottom;
|
||||
uint8_t bitmap_col;
|
||||
uint8_t bitmap_row_first;
|
||||
uint8_t bitmap_row_last;
|
||||
uint8_t bitmap_shift;
|
||||
} buf_bitmap_boundry_t;
|
||||
|
||||
static void _getBoundry(OLED_HandleTypeDef *hOled, buf_bitmap_boundry_t *boundry, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y)
|
||||
{
|
||||
if (pos_x < 0)
|
||||
{
|
||||
boundry->bitmap_col = pos_x * -1;
|
||||
boundry->buf_col_first = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
boundry->bitmap_col = 0;
|
||||
boundry->buf_col_first = pos_x;
|
||||
}
|
||||
|
||||
if (pos_y < 0)
|
||||
{
|
||||
boundry->bitmap_shift = 8 + (pos_y % 8);
|
||||
boundry->bitmap_row_first = (pos_y / 8) * (-1) + 1;
|
||||
boundry->buf_row_first = 0;
|
||||
boundry->buf_mask_top = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
boundry->bitmap_shift = pos_y % 8;
|
||||
boundry->bitmap_row_first = 0;
|
||||
boundry->buf_row_first = pos_y / 8;
|
||||
boundry->buf_mask_top = 0xFF >> (8 - boundry->bitmap_shift);
|
||||
}
|
||||
boundry->buf_mask_bottom = 0xFF << ((pos_y + bitmap_height) % 8);
|
||||
if (boundry->buf_mask_bottom == 0xFF)
|
||||
{
|
||||
boundry->buf_mask_bottom = 0;
|
||||
}
|
||||
|
||||
if ((bitmap_width + pos_x) > hOled->Width)
|
||||
{
|
||||
boundry->buf_col_last = hOled->Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
boundry->buf_col_last = bitmap_width + pos_x;
|
||||
}
|
||||
|
||||
if (bitmap_height + pos_y > hOled->Height)
|
||||
{
|
||||
boundry->buf_row_last = hOled->Height / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
boundry->buf_row_last = (bitmap_height + pos_y + 7) / 8;
|
||||
}
|
||||
|
||||
boundry->bitmap_row_last = (pos_y + bitmap_height) / 8;
|
||||
boundry->bitmap_max_idx = bitmap_width * ((bitmap_height + 7) / 8);
|
||||
}
|
||||
|
||||
static inline uint8_t _getBitmapByte(const uint8_t *bitmap, uint16_t index, GFX_Color_t color)
|
||||
{
|
||||
switch (color)
|
||||
{
|
||||
case INVERSE:
|
||||
return ~(bitmap[index]);
|
||||
case WHITE:
|
||||
return 0xFF;
|
||||
case BLACK:
|
||||
return 0x00;
|
||||
default:
|
||||
return bitmap[index];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief A function that writes a bitmap into the buffer at the given position.
|
||||
* 0,0 -------->x
|
||||
* |
|
||||
* |
|
||||
* \ /
|
||||
* y
|
||||
* @param bitmap A pointer to bitmap array.
|
||||
* @param bitmap_width Bitmap witdh in pixels.
|
||||
* @param bitmap_height Bitmap height in pixels.
|
||||
* @param pos_x Position x in the display
|
||||
* @param pos_y Position y in the display
|
||||
* @param color NORMAL (2) normal mode or INVERSE(3) mode for bitmap
|
||||
* WHITE (0) or BLACK (1) for fill screen
|
||||
*/
|
||||
void writeBitmap(OLED_HandleTypeDef *hOled, const uint8_t *bitmap, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y, GFX_Color_t color)
|
||||
{
|
||||
if (bitmap_width + pos_x < 0 || bitmap_height + pos_y < 0)
|
||||
return;
|
||||
|
||||
uint16_t tmp_buf16, bitmap_idx, buf_idx;
|
||||
uint8_t tmp_bitmap, bitmap_row;
|
||||
|
||||
buf_bitmap_boundry_t b;
|
||||
_getBoundry(hOled, &b, bitmap_width, bitmap_height, pos_x, pos_y);
|
||||
|
||||
for (uint8_t col = b.buf_col_first; col < b.buf_col_last; col++, b.bitmap_col++)
|
||||
{
|
||||
tmp_buf16 = 0;
|
||||
bitmap_row = b.bitmap_row_first;
|
||||
|
||||
if (b.bitmap_row_first > 0)
|
||||
{
|
||||
tmp_buf16 = _getBitmapByte(bitmap, bitmap_width * (b.bitmap_row_first - 1) + b.bitmap_col, color) >> (8 - b.bitmap_shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_buf16 = hOled->Buffer[b.buf_row_first * hOled->Width + col] & b.buf_mask_top;
|
||||
}
|
||||
|
||||
for (uint8_t buf_row = b.buf_row_first; buf_row < b.buf_row_last; buf_row++, bitmap_row++)
|
||||
{
|
||||
bitmap_idx = bitmap_width * bitmap_row + b.bitmap_col;
|
||||
buf_idx = buf_row * hOled->Width + col;
|
||||
|
||||
if (bitmap_idx < b.bitmap_max_idx)
|
||||
{
|
||||
tmp_bitmap = _getBitmapByte(bitmap, bitmap_idx, color);
|
||||
tmp_buf16 |= tmp_bitmap << b.bitmap_shift;
|
||||
}
|
||||
|
||||
if (b.bitmap_row_last == buf_row)
|
||||
{
|
||||
hOled->Buffer[buf_idx] = (hOled->Buffer[buf_idx] & b.buf_mask_bottom) | (tmp_buf16 & ~(b.buf_mask_bottom));
|
||||
}
|
||||
else
|
||||
{
|
||||
hOled->Buffer[buf_idx] = (uint8_t)tmp_buf16;
|
||||
}
|
||||
tmp_buf16 = tmp_buf16 >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeSlashLine(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, int16_t x1, int16_t y1, GFX_Color_t color)
|
||||
{
|
||||
uint8_t steep = _diff(y1, y0) > _diff(x1, x0); // bool
|
||||
if (steep)
|
||||
{
|
||||
_swap_int16_t(x0, y0);
|
||||
_swap_int16_t(x1, y1);
|
||||
}
|
||||
|
||||
if (x0 > x1)
|
||||
{
|
||||
_swap_int16_t(x0, x1);
|
||||
_swap_int16_t(y0, y1);
|
||||
}
|
||||
|
||||
int16_t dx = x1 - x0;
|
||||
int16_t dy = _diff(y1, y0);
|
||||
int16_t err = dx >> 1;
|
||||
int16_t step = (y0 < y1) ? 1 : -1;
|
||||
|
||||
for (; x0 <= x1; x0++)
|
||||
{
|
||||
if (steep)
|
||||
{
|
||||
writePixel(hOled, y0, x0, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
writePixel(hOled, x0, y0, color);
|
||||
}
|
||||
err -= dy;
|
||||
if (err < 0)
|
||||
{
|
||||
err += dx;
|
||||
y0 += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Write a perfectly vertical line
|
||||
@param x Top-most x coordinate
|
||||
@param y Top-most y coordinate
|
||||
@param height Height in pixels
|
||||
@param color Color of pixel WHITE(0), BLACK(1) or INVERSE(2)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void writeVerticalLine(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t height, GFX_Color_t color)
|
||||
{
|
||||
for (int16_t i = y; i < y + height; i++)
|
||||
{
|
||||
writePixel(hOled, x, i, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Write a perfectly horizontal line
|
||||
@param x Left-most x coordinate
|
||||
@param y Left-most y coordinate
|
||||
@param width Width in pixels
|
||||
@param color Color of pixel WHITE(0), BLACK(1) or INVERSE(2)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void writeHorizontalLine(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t width, GFX_Color_t color)
|
||||
{
|
||||
for (int16_t i = x; i < x + width; i++)
|
||||
{
|
||||
writePixel(hOled, i, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
void writeRect(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t width, int16_t height, GFX_Color_t color)
|
||||
{
|
||||
writeHorizontalLine(hOled, x, y, width, color);
|
||||
writeHorizontalLine(hOled, x, y + height - 1, width, color);
|
||||
writeVerticalLine(hOled, x, y, height, color);
|
||||
writeVerticalLine(hOled, x + width - 1, y, height, color);
|
||||
}
|
||||
|
||||
void writeFillRect(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t width, int16_t height, GFX_Color_t color)
|
||||
{
|
||||
writeBitmap(hOled, NULL, width, height, x, y, color);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Draw a circle outline
|
||||
@param x0 Center-point x coordinate
|
||||
@param y0 Center-point y coordinate
|
||||
@param radius Radius of circle
|
||||
@param color 16-bit 5-6-5 Color to draw with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void writeCircle(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, uint8_t radius, GFX_Color_t color)
|
||||
{
|
||||
|
||||
int16_t f = 1 - radius;
|
||||
int16_t ddF_x = 1;
|
||||
int16_t ddF_y = -2 * radius;
|
||||
int16_t x = 0;
|
||||
int16_t y = radius;
|
||||
|
||||
writePixel(hOled, x0, y0 + radius, color);
|
||||
writePixel(hOled, x0, y0 - radius, color);
|
||||
writePixel(hOled, x0 + radius, y0, color);
|
||||
writePixel(hOled, x0 - radius, y0, color);
|
||||
|
||||
while (x < y)
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
writePixel(hOled, x0 + x, y0 + y, color);
|
||||
writePixel(hOled, x0 - x, y0 + y, color);
|
||||
writePixel(hOled, x0 + x, y0 - y, color);
|
||||
writePixel(hOled, x0 - x, y0 - y, color);
|
||||
writePixel(hOled, x0 + y, y0 + x, color);
|
||||
writePixel(hOled, x0 - y, y0 + x, color);
|
||||
writePixel(hOled, x0 + y, y0 - x, color);
|
||||
writePixel(hOled, x0 - y, y0 - x, color);
|
||||
}
|
||||
endWrite();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Quarter-circle drawer, used to do circles and roundrects
|
||||
@param x0 Center-point x coordinate
|
||||
@param y0 Center-point y coordinate
|
||||
@param radius Radius of circle
|
||||
@param corner Mask bit #1 or bit #2 to indicate which quarters of
|
||||
the circle we're doing
|
||||
@param color 16-bit 5-6-5 Color to draw with
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void writeQuarterCircle(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, uint8_t radius, CIRC_Corners_t corner, GFX_Color_t color)
|
||||
{
|
||||
int16_t f = 1 - radius;
|
||||
int16_t ddF_x = 1;
|
||||
int16_t ddF_y = -2 * radius;
|
||||
int16_t x = 0;
|
||||
int16_t y = radius;
|
||||
|
||||
while (x < y)
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
if (corner & BOTTOM_LEFT)
|
||||
{
|
||||
writePixel(hOled, x0 + x, y0 + y, color);
|
||||
writePixel(hOled, x0 + y, y0 + x, color);
|
||||
}
|
||||
if (corner & BOTTOM_RIGHT)
|
||||
{
|
||||
writePixel(hOled, x0 + x, y0 - y, color);
|
||||
writePixel(hOled, x0 + y, y0 - x, color);
|
||||
}
|
||||
if (corner & TOP_LEFT)
|
||||
{
|
||||
writePixel(hOled, x0 - y, y0 + x, color);
|
||||
writePixel(hOled, x0 - x, y0 + y, color);
|
||||
}
|
||||
if (corner & TOP_RIGHT)
|
||||
{
|
||||
writePixel(hOled, x0 - y, y0 - x, color);
|
||||
writePixel(hOled, x0 - x, y0 - y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
oled/gfx.h
Normal file
39
oled/gfx.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "oled.h"
|
||||
|
||||
#ifndef _swap_int16_t
|
||||
#define _swap_int16_t(a, b) \
|
||||
{ \
|
||||
int16_t t = a; \
|
||||
a = b; \
|
||||
b = t; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _diff
|
||||
#define _diff(a, b) ((a > b) ? (a - b) : (b - a))
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WHITE,
|
||||
BLACK,
|
||||
NORMAL,
|
||||
INVERSE
|
||||
} GFX_Color_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TOP_RIGHT = 1,
|
||||
BOTTOM_RIGHT = 2,
|
||||
BOTTOM_LEFT = 4,
|
||||
TOP_LEFT = 8
|
||||
} CIRC_Corners_t;
|
||||
|
||||
void writePixel(OLED_HandleTypeDef *hOled, uint8_t x, uint8_t y, GFX_Color_t color);
|
||||
void writeBitmap(OLED_HandleTypeDef *hOled, const uint8_t *bitmap, uint8_t bitmap_width, uint8_t bitmap_height, int8_t pos_x, int8_t pos_y, GFX_Color_t color);
|
||||
void writeSlashLine(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, int16_t x1, int16_t y1, GFX_Color_t color);
|
||||
void writeVerticalLine(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t height, GFX_Color_t color);
|
||||
void writeHorizontalLine(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t width, GFX_Color_t color);
|
||||
void writeRect(OLED_HandleTypeDef *hOled, int16_t x, int16_t y, int16_t width, int16_t height, GFX_Color_t color);
|
||||
void writeCircle(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, uint8_t radius, GFX_Color_t color);
|
||||
void writeQuarterCircle(OLED_HandleTypeDef *hOled, int16_t x0, int16_t y0, uint8_t radius, CIRC_Corners_t corner, GFX_Color_t color);
|
||||
102
oled/oled.c
Normal file
102
oled/oled.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <stdlib.h>
|
||||
// #include <assert.h>
|
||||
#include "oled.h"
|
||||
#include "ssd1306.h"
|
||||
#include "sh1106.h"
|
||||
|
||||
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType)
|
||||
{
|
||||
// static_assert(hOled != NULL, "brak pointera");
|
||||
if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
hOled->hi2c = NULL;
|
||||
hOled->DevAddress = DevAddress;
|
||||
hOled->Width = Width;
|
||||
hOled->Height = Height;
|
||||
hOled->OledType = OledType;
|
||||
hOled->BufSize = Width * ((Height + 7) / 8);
|
||||
hOled->Buffer = (uint8_t *)malloc(hOled->BufSize);
|
||||
|
||||
if (hOled->Buffer == NULL)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
if (hOled == NULL || hi2c == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hOled->Buffer == NULL || hOled->BufSize == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hOled->hi2c = hi2c;
|
||||
|
||||
switch (hOled->OledType)
|
||||
{
|
||||
case SSD1306:
|
||||
SSD1306_Init(hOled);
|
||||
break;
|
||||
case SH1106:
|
||||
SH1106_Init(hOled);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void oled_display_all(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
if (hOled == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (hOled->OledType)
|
||||
{
|
||||
case SSD1306:
|
||||
SSD1306_display_all(hOled);
|
||||
break;
|
||||
case SH1106:
|
||||
SH1106_display_all(hOled);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
if (hOled == NULL)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
OLED_SendStatus_t sendStatus;
|
||||
switch (hOled->OledType)
|
||||
{
|
||||
case SSD1306:
|
||||
sendStatus = SSD1306_display_page(hOled);
|
||||
break;
|
||||
case SH1106:
|
||||
sendStatus = SH1106_display_page(hOled);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return sendStatus;
|
||||
}
|
||||
|
||||
37
oled/oled.h
Normal file
37
oled/oled.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define I2C_COMMAND 0x00
|
||||
#define I2C_DATA 0x40
|
||||
#define I2C_TIMEOUT 100
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNKNOWN,
|
||||
SSD1306,
|
||||
SH1106
|
||||
} OLED_DisplayType_t;
|
||||
|
||||
typedef enum{
|
||||
ERROR,
|
||||
SENDPAGE,
|
||||
SENDALL
|
||||
} OLED_SendStatus_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
I2C_HandleTypeDef *hi2c;
|
||||
OLED_DisplayType_t OledType;
|
||||
uint8_t DevAddress;
|
||||
uint8_t Width;
|
||||
uint8_t Height;
|
||||
uint8_t *Buffer;
|
||||
uint16_t BufSize;
|
||||
|
||||
} OLED_HandleTypeDef;
|
||||
|
||||
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType);
|
||||
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c);
|
||||
void oled_display_all(OLED_HandleTypeDef *hOled);
|
||||
OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled);
|
||||
62
oled/sh1106/sh1106.c
Normal file
62
oled/sh1106/sh1106.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "oled.h"
|
||||
#include "sh1106.h"
|
||||
#include "connection.h"
|
||||
|
||||
void SH1106_Init(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
uint8_t display = SH1106_DISPLAYOFF;
|
||||
oled_SendCommand(hOled, &display, 1);
|
||||
|
||||
uint8_t config[] = {
|
||||
SH1106_LOWCOLADDR | 0x00, // 0x00h (0000 XXXX)
|
||||
SH1106_HIGHCOLADDR | 0x00, // 0x10h (0001 XXXX)
|
||||
SH1106_PUMPVOLTAGE | 0x02, // 0x32h (0011 00XX)
|
||||
SH1106_LINEADDRESS | 0x00, // 0x40h (01XX XXXX)
|
||||
SH1106_CONTRASTMODE, SH1106_CONTRASTVALUE, // (1000 0001) // 0x80h (0x00h - 0xFFh) (XXXX XXXX)
|
||||
SH1106_SEGMENTREMAP | 0x00, // 0xA0h (1010 000X) right(0), left(1)
|
||||
SH1106_ENTIREDISPALY | 0x00, // 0xA4h (1010 010X) normal(0), entire(1)
|
||||
SH1106_NORMALORREVERS | 0x00, // 0xA6h (1010 011X) normal(0), reverse(1)
|
||||
SH1106_MULTIPLEXMODE, SH1106_MILTIPLEXVALUE, // (1010 1000) // 0x3Fh (00XX XXXX) (0x00h - 0x3Fh)
|
||||
SH1106_DCCONTROLMODE, SH1106_DCCONTROLVALON, // (1010 1101) // 0x8Bh (1000 101X) ON(1), OFF(0)
|
||||
SH1106_PAGEADDRESS | 0x00, // 0xB0h (1011 XXXX)
|
||||
SH1106_OUTPUTSCANDIR | 0x00, // 0xC0h (1100 X000) Scan from COM0 to COM [N- 1] (0x00) or Scan from COM [N-1] to COM0 (0x08)
|
||||
SH1106_OFFSETMODE, SH1106_OFFSETVALUE, // (1101 0011) // 0x00h (00XX XXXX) COM0-63
|
||||
SH1106_DIVRATIOFREQM, SH1106_DIVRATIOFREQV, // (1101 0101) // 0x50h (FFFF DDDD) Frequency, Divide
|
||||
SH1106_CHARGEMODE, SH1106_CHARGEVALUE, // (1101 1001) // 0x22h (DDDD PPPP) Dis-charge Period, Pre-charge Period
|
||||
SH1106_COMPADSCONFMODE, SH1106_COMPADSCONFVAL, // (1101 1010) // 0x12h (000X 0010)
|
||||
SH1106_VCOMDESMODE, SH1106_VCOMDESVALUE // (1101 1101) // 0x35h (XXXX XXXX) VCOM (Beta x Vref)
|
||||
};
|
||||
oled_SendCommand(hOled, config, sizeof(config));
|
||||
|
||||
display = SH1106_DISPLAYON;
|
||||
oled_SendCommand(hOled, &display, 1);
|
||||
}
|
||||
|
||||
void SH1106_display_all(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
while (SH1106_display_page(hOled) != SENDALL);
|
||||
}
|
||||
|
||||
OLED_SendStatus_t SH1106_display_page(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
static uint8_t page = 0;
|
||||
|
||||
uint8_t config[] = {
|
||||
SH1106_PAGEADDRESS | page,
|
||||
SH1106_LOWCOLADDR | 0x00,
|
||||
SH1106_HIGHCOLADDR | 0x00,
|
||||
};
|
||||
oled_SendCommand(hOled, config, sizeof(config));
|
||||
|
||||
oled_SendData(hOled, hOled->Buffer + (page * hOled->Width), hOled->Width);
|
||||
|
||||
if (++page > 7)
|
||||
{
|
||||
page = 0;
|
||||
return SENDALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SENDPAGE;
|
||||
}
|
||||
}
|
||||
33
oled/sh1106/sh1106.h
Normal file
33
oled/sh1106/sh1106.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#define SH1106_LOWCOLADDR 0x00 // 0x00h (0000 XXXX)
|
||||
#define SH1106_HIGHCOLADDR 0x10 // 0x10h (0001 XXXX)
|
||||
#define SH1106_PUMPVOLTAGE 0x30 // 0x32h (0011 00XX)
|
||||
#define SH1106_LINEADDRESS 0x40 // 0x40h (01XX XXXX)
|
||||
#define SH1106_CONTRASTMODE 0x81 // (1000 0001)
|
||||
#define SH1106_CONTRASTVALUE 0x80 // 0x80h (0x00h - 0xFFh) (XXXX XXXX)
|
||||
#define SH1106_SEGMENTREMAP 0xA0 // 0xA0h (1010 000X) right(0), left(1)
|
||||
#define SH1106_ENTIREDISPALY 0xA4 // 0xA4h (1010 010X) normal(0), entire(1)
|
||||
#define SH1106_NORMALORREVERS 0xA6 // 0xA6h (1010 011X) normal(0), reverse(1)
|
||||
#define SH1106_MULTIPLEXMODE 0xA8 // (1010 1000)
|
||||
#define SH1106_MILTIPLEXVALUE 0x3F // 0x3Fh (00XX XXXX) (0x00h - 0x3Fh)
|
||||
#define SH1106_DCCONTROLMODE 0xAD // (1010 1101)
|
||||
#define SH1106_DCCONTROLVALON 0x8B // 0x8Bh (1000 101X) ON(1), OFF(0)
|
||||
#define SH1106_DISPLAYOFF 0xAE // 0xAEh (1010 111X) ON(1), OFF(0)
|
||||
#define SH1106_DISPLAYON 0xAF // 0xAEh (1010 111X) ON(1), OFF(0)
|
||||
#define SH1106_PAGEADDRESS 0xB0 // 0xB0h (1011 XXXX)
|
||||
#define SH1106_OUTPUTSCANDIR 0xC0 // 0xC0h (1100 X000) Scan from COM0 to COM [N- 1] (0) or Scan from COM [N-1] to COM0 (1).
|
||||
#define SH1106_OFFSETMODE 0xD3 // (1101 0011)
|
||||
#define SH1106_OFFSETVALUE 0x00 // 0x00h (00XX XXXX) COM0-63
|
||||
#define SH1106_DIVRATIOFREQM 0xD5 // (1101 0101)
|
||||
#define SH1106_DIVRATIOFREQV 0x50 // 0x50h (FFFF DDDD) Frequency, Divide
|
||||
#define SH1106_CHARGEMODE 0xD9 // (1101 1001)
|
||||
#define SH1106_CHARGEVALUE 0x22 // 0x22h (DDDD PPPP) Dis-charge Period, Pre-charge Period
|
||||
#define SH1106_COMPADSCONFMODE 0xDA // (1101 1010)
|
||||
#define SH1106_COMPADSCONFVAL 0x12 // 0x12h (000X 0010)
|
||||
#define SH1106_VCOMDESMODE 0xDD // (1101 1101)
|
||||
#define SH1106_VCOMDESVALUE 0x35 // 0x35h (XXXX XXXX) VCOM (Beta x Vref)
|
||||
|
||||
void SH1106_Init(OLED_HandleTypeDef *hOled);
|
||||
void SH1106_display_all(OLED_HandleTypeDef *hOled);
|
||||
OLED_SendStatus_t SH1106_display_page(OLED_HandleTypeDef *hOled);
|
||||
81
oled/ssd1306/ssd1306.c
Normal file
81
oled/ssd1306/ssd1306.c
Normal file
@@ -0,0 +1,81 @@
|
||||
|
||||
#include "ssd1306.h"
|
||||
#include "connection.h"
|
||||
|
||||
void SSD1306_Init(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
uint8_t comPins = 0x02;
|
||||
uint8_t contrast = 0x8F;
|
||||
|
||||
if ((hOled->Width == 128) && (hOled->Height == 32)) {
|
||||
comPins = 0x02;
|
||||
contrast = 0x0F;
|
||||
} else if ((hOled->Width == 128) && (hOled->Height == 64)) {
|
||||
comPins = 0x12;
|
||||
contrast = 0xCF;
|
||||
} else if ((hOled->Width == 96) && (hOled->Height == 16)) {
|
||||
comPins = 0x02; // ada x12
|
||||
contrast = 0xAF;
|
||||
}
|
||||
|
||||
uint8_t display = SSD1306_DISPLAYOFF;
|
||||
oled_SendCommand(hOled, &display, 1);
|
||||
|
||||
uint8_t config[] = {
|
||||
SSD1306_SETMULTIPLEX, hOled->Height -1,
|
||||
SSD1306_SETDISPLAYOFFSET, 0x00,
|
||||
SSD1306_SETSTARTLINE | 0x00,
|
||||
SSD1306_SEGREMAP | 0x01,
|
||||
SSD1306_COMSCANDEC,
|
||||
SSD1306_SETCOMPINS, comPins,
|
||||
SSD1306_SETCONTRAST, contrast,
|
||||
SSD1306_DISPLAYALLON_RESUME,
|
||||
SSD1306_NORMALDISPLAY,
|
||||
SSD1306_SETDISPLAYCLOCKDIV, 0x80,
|
||||
SSD1306_CHARGEPUMP, 0x14,
|
||||
SSD1306_MEMORYMODE, 0x00,
|
||||
SSD1306_DEACTIVATE_SCROLL,
|
||||
SSD1306_SETPRECHARGE, 0xF1,
|
||||
SSD1306_SETVCOMDETECT, 0x40
|
||||
};
|
||||
|
||||
oled_SendCommand(hOled, config, sizeof(config));
|
||||
|
||||
display = SSD1306_DISPLAYOFF;
|
||||
oled_SendCommand(hOled, &display, 1);
|
||||
}
|
||||
|
||||
void SSD1306_display_all(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
|
||||
uint8_t config[] = {
|
||||
SSD1306_PAGEADDR, 0x00, 0x07, //cmd, start_page, end_page
|
||||
SSD1306_COLUMNADDR, 0x00, hOled->Width - 1 //cmd, start_col, end_col
|
||||
};
|
||||
oled_SendCommand(hOled, config, sizeof(config));
|
||||
|
||||
oled_SendData(hOled, hOled->Buffer, hOled->BufSize);
|
||||
}
|
||||
|
||||
OLED_SendStatus_t SSD1306_display_page(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
static uint8_t page = 0;
|
||||
|
||||
uint8_t config[] = {
|
||||
SSD1306_PAGEADDR, page, page,
|
||||
SSD1306_COLUMNADDR, 0x00, hOled->Width - 1
|
||||
};
|
||||
oled_SendCommand(hOled, config, sizeof(config));
|
||||
|
||||
oled_SendData(hOled, hOled->Buffer + (page * hOled->Width), hOled->Width);
|
||||
|
||||
if (++page > 7)
|
||||
{
|
||||
page = 0;
|
||||
return SENDALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SENDPAGE;
|
||||
}
|
||||
}
|
||||
43
oled/ssd1306/ssd1306.h
Normal file
43
oled/ssd1306/ssd1306.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "oled.h"
|
||||
|
||||
#define SSD1306_MEMORYMODE 0x20 ///< See datasheet
|
||||
#define SSD1306_COLUMNADDR 0x21 ///< See datasheet
|
||||
#define SSD1306_PAGEADDR 0x22 ///< See datasheet
|
||||
#define SSD1306_SETCONTRAST 0x81 ///< See datasheet
|
||||
#define SSD1306_CHARGEPUMP 0x8D ///< See datasheet
|
||||
#define SSD1306_SEGREMAP 0xA0 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON_RESUME 0xA4 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON 0xA5 ///< Not currently used
|
||||
#define SSD1306_NORMALDISPLAY 0xA6 ///< See datasheet
|
||||
#define SSD1306_INVERTDISPLAY 0xA7 ///< See datasheet
|
||||
#define SSD1306_SETMULTIPLEX 0xA8 ///< See datasheet
|
||||
#define SSD1306_DISPLAYOFF 0xAE ///< See datasheet
|
||||
#define SSD1306_DISPLAYON 0xAF ///< See datasheet
|
||||
#define SSD1306_COMSCANINC 0xC0 ///< Not currently used
|
||||
#define SSD1306_COMSCANDEC 0xC8 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYOFFSET 0xD3 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 ///< See datasheet
|
||||
#define SSD1306_SETPRECHARGE 0xD9 ///< See datasheet
|
||||
#define SSD1306_SETCOMPINS 0xDA ///< See datasheet
|
||||
#define SSD1306_SETVCOMDETECT 0xDB ///< See datasheet
|
||||
|
||||
#define SSD1306_SETLOWCOLUMN 0x00 ///< Not currently used
|
||||
#define SSD1306_SETHIGHCOLUMN 0x10 ///< Not currently used
|
||||
#define SSD1306_SETSTARTLINE 0x40 ///< See datasheet
|
||||
|
||||
#define SSD1306_EXTERNALVCC 0x01 ///< External display voltage source
|
||||
#define SSD1306_SWITCHCAPVCC 0x02 ///< Gen. display voltage from 3.3V
|
||||
|
||||
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 ///< Init rt scroll
|
||||
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 ///< Init left scroll
|
||||
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 ///< Init diag scroll
|
||||
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A ///< Init diag scroll
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E ///< Stop scroll
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range
|
||||
|
||||
void SSD1306_Init(OLED_HandleTypeDef *hOled);
|
||||
void SSD1306_display_all(OLED_HandleTypeDef *hOled);
|
||||
OLED_SendStatus_t SSD1306_display_page(OLED_HandleTypeDef *hOled);
|
||||
21
test/cmd_parser/CMakeLists.txt
Normal file
21
test/cmd_parser/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(TEST_NAME cmd_parser_test)
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
../../cmd_parser
|
||||
helpers/inc
|
||||
../../utility/fff
|
||||
)
|
||||
|
||||
set(SRCS
|
||||
../../cmd_parser/cmd_parser.c
|
||||
|
||||
# helpers/src/led_cmd.c
|
||||
cmd_parser_test.c
|
||||
)
|
||||
|
||||
add_definitions(-DTEST)
|
||||
add_executable(${TEST_NAME} ${SRCS})
|
||||
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIRS})
|
||||
283
test/cmd_parser/cmd_parser_test.c
Normal file
283
test/cmd_parser/cmd_parser_test.c
Normal file
@@ -0,0 +1,283 @@
|
||||
#include "unity.h"
|
||||
#include "fff.h"
|
||||
#include "cmd_parser.h"
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
FAKE_VALUE_FUNC(result_t, parse_callback, char, char *);
|
||||
|
||||
cmd_t led_cmd = {.name = "led", .parser = parse_callback};
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
RESET_FAKE(parse_callback);
|
||||
FFF_RESET_HISTORY();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_splittoken1(void)
|
||||
{
|
||||
char msg[] = "led";
|
||||
parse_callback_fake.return_val = CMD_OK;
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(1, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken2(void)
|
||||
{
|
||||
char msg[] = "led set";
|
||||
parse_callback_fake.return_val = CMD_OK;
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_ARG, parse_callback_fake.arg0_history[0]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("set", parse_callback_fake.arg1_history[0], 3);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken3(void)
|
||||
{
|
||||
char msg[] = "led set -p";
|
||||
parse_callback_fake.return_val = CMD_OK;
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(3, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken4(void)
|
||||
{
|
||||
char msg[] = "led set -p 50";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(4, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
|
||||
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[2]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("50", parse_callback_fake.arg1_history[2], 2);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken5(void)
|
||||
{
|
||||
char msg[] = "led set -p 50 -l";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(5, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken6(void)
|
||||
{
|
||||
char msg[] = "led set -p 50 -l Atop, Btop, Ctop";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken7(void)
|
||||
{
|
||||
char msg[] = "led set -p -l Atop, Btop, Ctop";
|
||||
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(7, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[2]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[2]);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[3], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[4], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[5], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken8(void)
|
||||
{
|
||||
char msg[] = "led set -p -l Atop, Btop, Ctop test";
|
||||
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK, CMD_OK, CMD_OK, CMD_UNKNOWN, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(9, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_ARG, parse_callback_fake.arg0_history[7]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", parse_callback_fake.arg1_history[7], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken9(void)
|
||||
{
|
||||
char msg[] = "led set -p -l Atop, Btop, Wrong test";
|
||||
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK, CMD_OK, CMD_UNKNOWN, CMD_UNKNOWN, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken10(void)
|
||||
{
|
||||
char msg[] = "led set -p50";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(4, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
|
||||
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[2]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("50", parse_callback_fake.arg1_history[2], 2);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken11(void)
|
||||
{
|
||||
char msg[] = "led set -p50 -l Atop,Btop,Ctop";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken12(void)
|
||||
{
|
||||
char msg[] = "led set -p50 -lAtop,Btop,Ctop";
|
||||
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
|
||||
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
|
||||
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
void test_splittoken13(void)
|
||||
{
|
||||
char msg[] = "led wrong";
|
||||
result_t returnValue[] = {CMD_UNKNOWN, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, 5);
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
|
||||
}
|
||||
|
||||
void test_splittoken14(void)
|
||||
{
|
||||
char msg[] = "led wrong -p 50 -l Atop,Btop,Ctop";
|
||||
result_t returnValue[] = {CMD_UNKNOWN, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
// TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
|
||||
void test_splittoken15(void)
|
||||
{
|
||||
char msg[] = "led set -X 50 -l Atop,Btop,Ctop";
|
||||
result_t returnValue[] = {CMD_OK, CMD_UNKNOWN, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
|
||||
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
|
||||
msg_parse(msg);
|
||||
TEST_ASSERT_EQUAL(3, parse_callback_fake.call_count);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
|
||||
// TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
|
||||
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
|
||||
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cmd_t led_cmd = {.name = "led", .parser = parse_callback};
|
||||
const cmd_t *cmd_list[] = {&led_cmd};
|
||||
cmd_parser_init(cmd_list, sizeof(cmd_list)/sizeof(cmd_list[0]) );
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_splittoken1);
|
||||
RUN_TEST(test_splittoken2);
|
||||
RUN_TEST(test_splittoken3);
|
||||
RUN_TEST(test_splittoken4);
|
||||
RUN_TEST(test_splittoken5);
|
||||
RUN_TEST(test_splittoken6);
|
||||
RUN_TEST(test_splittoken7);
|
||||
RUN_TEST(test_splittoken8);
|
||||
RUN_TEST(test_splittoken9);
|
||||
RUN_TEST(test_splittoken10);
|
||||
RUN_TEST(test_splittoken11);
|
||||
RUN_TEST(test_splittoken12);
|
||||
RUN_TEST(test_splittoken13);
|
||||
RUN_TEST(test_splittoken14);
|
||||
RUN_TEST(test_splittoken15);
|
||||
return UNITY_END();
|
||||
}
|
||||
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal file
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "main.h"
|
||||
#include "cmd_parser.h"
|
||||
|
||||
/*
|
||||
Usage: led set|get [-p PNUM | --power=PNUM] [-w CHOICES | --which=CHOICES] [-m COICES | --mode=CHOICES]
|
||||
-p, --power set or get power 0-100
|
||||
-w, --which set or get specific leds [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]
|
||||
-m, --mode set or get mode of operation [allways_on, scan]
|
||||
*/
|
||||
// cmd_parser_t led_cmd;
|
||||
|
||||
result_t parse_callback(char key, char *arg);
|
||||
62
test/cmd_parser/helpers/src/led_cmd.c
Normal file
62
test/cmd_parser/helpers/src/led_cmd.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "led_cmd.h"
|
||||
|
||||
enum {set, get};
|
||||
|
||||
option_t set_options[] = {
|
||||
{
|
||||
.opt_id = 'p',
|
||||
.name = "power",
|
||||
.flags = SINGLE_VALE,
|
||||
.description = "sets the power of the light",
|
||||
},
|
||||
|
||||
{
|
||||
.opt_id = 'l',
|
||||
.name = "led",
|
||||
.flags = MULTI_VALUE,
|
||||
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
option_t get_options[] = {
|
||||
{
|
||||
.opt_id = 'p',
|
||||
.name = "power",
|
||||
.flags = NO_VALUE,
|
||||
.description = "gets the power of the light",
|
||||
},
|
||||
|
||||
{
|
||||
.opt_id = 'l',
|
||||
.name = "led",
|
||||
.flags = MULTI_VALUE,
|
||||
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
argument_t arguments[] = {
|
||||
{
|
||||
.name = "set",
|
||||
.arg_id = set,
|
||||
.options = set_options,
|
||||
.opt_num = sizeof(set_options) / (sizeof(set_options[0])),
|
||||
.description = "allows to set operating parameters",
|
||||
},
|
||||
{
|
||||
.name = "get",
|
||||
.arg_id = get,
|
||||
.options = get_options,
|
||||
.opt_num = sizeof(get_options) / (sizeof(get_options[0])),
|
||||
.description = "allows to get operating parameters",
|
||||
},
|
||||
};
|
||||
|
||||
cmd_parser_t led_cmd = {
|
||||
.name = "led",
|
||||
.arguments = arguments,
|
||||
.arg_num = sizeof(arguments) / sizeof(arguments[0]),
|
||||
.description = "allows to controll and check leds",
|
||||
.cmd_parser = parse_callback,
|
||||
};
|
||||
@@ -1,17 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(TEST_NAME oled)
|
||||
set(TEST_NAME oled_test)
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
../../oled
|
||||
../../oled/ssd1306
|
||||
../../oled/sh1106
|
||||
helpers/inc
|
||||
)
|
||||
|
||||
set(SRCS
|
||||
../../oled/oled.c
|
||||
../../oled/connection.c
|
||||
../../oled/ssd1306/ssd1306.c
|
||||
../../oled/sh1106/sh1106.c
|
||||
|
||||
helpers/src/mock_i2c.c
|
||||
oled_test.c
|
||||
)
|
||||
|
||||
add_definitions(-DTEST)
|
||||
add_executable(${TEST_NAME} ${SRCS})
|
||||
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIR})
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIRS})
|
||||
18
test/oled/helpers/inc/main.h
Normal file
18
test/oled/helpers/inc/main.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t dummy;
|
||||
}I2C_HandleTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HAL_OK = 0x00U,
|
||||
HAL_ERROR = 0x01U,
|
||||
HAL_BUSY = 0x02U,
|
||||
HAL_TIMEOUT = 0x03
|
||||
} HAL_StatusTypeDef;
|
||||
|
||||
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
||||
14
test/oled/helpers/src/mock_i2c.c
Normal file
14
test/oled/helpers/src/mock_i2c.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "main.h"
|
||||
|
||||
|
||||
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
(void)hi2c;
|
||||
(void)DevAddress;
|
||||
(void)MemAddress;
|
||||
(void)MemAddSize;
|
||||
(void)pData;
|
||||
(void)Size;
|
||||
(void)Timeout;
|
||||
return HAL_OK;
|
||||
}
|
||||
50
test/oled/oled_test.c
Normal file
50
test/oled/oled_test.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "stdlib.h"
|
||||
#include "unity.h"
|
||||
#include "oled.h"
|
||||
#include "string.h"
|
||||
|
||||
OLED_HandleTypeDef* display;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// uint32_t size = sizeof(OLED_HandleTypeDef);
|
||||
// printf("size in B: %u\n", size);
|
||||
display = (OLED_HandleTypeDef*)malloc(sizeof(OLED_HandleTypeDef));
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
free(display);
|
||||
}
|
||||
|
||||
void test_configWithCorecctArgs(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = oled_Config(display, 0x0F, 128, 64, SH1106);
|
||||
|
||||
TEST_ASSERT_EQUAL(status, HAL_OK);
|
||||
TEST_ASSERT_NULL(display->hi2c);
|
||||
TEST_ASSERT_EQUAL(display->OledType, SH1106);
|
||||
TEST_ASSERT_EQUAL_HEX8(display->DevAddress, 0x0F);
|
||||
TEST_ASSERT_EQUAL(display->Width, 128);
|
||||
TEST_ASSERT_EQUAL(display->Height, 64);
|
||||
TEST_ASSERT_EQUAL(display->BufSize, 128*64/8);
|
||||
TEST_ASSERT_NOT_NULL(display->Buffer);
|
||||
}
|
||||
|
||||
void test_configWithoutPointerToDisplay(void)
|
||||
{
|
||||
HAL_StatusTypeDef status = oled_Config(NULL, 0x0F, 128, 64, SH1106);
|
||||
|
||||
TEST_ASSERT_EQUAL(status, HAL_ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_configWithCorecctArgs);
|
||||
RUN_TEST(test_configWithoutPointerToDisplay);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
6643
utility/fff/fff.h
Normal file
6643
utility/fff/fff.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user