minor changes
This commit is contained in:
2022-11-27 07:49:52 +01:00
parent d0b533daf9
commit 1b83af44e9
5 changed files with 56 additions and 17 deletions

14
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,14 @@
{
"files.associations": {
"climits": "c",
"cmath": "c",
"cstdarg": "c",
"cstdint": "c",
"cstdio": "c",
"cstdlib": "c",
"type_traits": "c",
"limits": "c",
"*.tcc": "c",
"typeinfo": "c"
}
}

View File

@@ -1,15 +1,18 @@
#include <stdlib.h> #include <stdlib.h>
// #include <assert.h>
#include "oled.h" #include "oled.h"
#include "ssd1306.h" #include "ssd1306.h"
#include "sh1106.h" #include "sh1106.h"
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType) 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) if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
{ {
return HAL_ERROR; return HAL_ERROR;
} }
hOled->hi2c = NULL;
hOled->DevAddress = DevAddress; hOled->DevAddress = DevAddress;
hOled->Width = Width; hOled->Width = Width;
hOled->Height = Height; hOled->Height = Height;
@@ -78,7 +81,7 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
{ {
if (hOled == NULL) if (hOled == NULL)
{ {
return; return ERROR;
} }
OLED_SendStatus_t sendStatus; OLED_SendStatus_t sendStatus;
switch (hOled->OledType) switch (hOled->OledType)
@@ -97,9 +100,3 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
return sendStatus; return sendStatus;
} }
int main(void)
{
OLED_HandleTypeDef display;
oled_Config(&display, 0x3C, 128, 64, SH1106);
}

View File

@@ -14,6 +14,7 @@ typedef enum
} OLED_DisplayType_t; } OLED_DisplayType_t;
typedef enum{ typedef enum{
ERROR,
SENDPAGE, SENDPAGE,
SENDALL SENDALL
} OLED_SendStatus_t; } OLED_SendStatus_t;
@@ -30,4 +31,7 @@ typedef struct
} OLED_HandleTypeDef; } OLED_HandleTypeDef;
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c); 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);

View File

@@ -10,12 +10,12 @@ set(INCLUDE_DIRS
) )
set(SRCS set(SRCS
# ../../oled/oled.c ../../oled/oled.c
# ../../oled/connection.c ../../oled/connection.c
# ../../oled/ssd1306/ssd1306.c ../../oled/ssd1306/ssd1306.c
# ../../oled/sh1106/sh1106.c ../../oled/sh1106/sh1106.c
# helpers/src/mock_i2c.c helpers/src/mock_i2c.c
oled_test.c oled_test.c
) )

View File

@@ -1,18 +1,41 @@
#include "stdlib.h"
#include "unity.h" #include "unity.h"
#include "oled.h"
#include "string.h"
OLED_HandleTypeDef* display;
void setUp(void) 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) void tearDown(void)
{ {
free(display);
} }
void test_one(void) void test_configWithCorecctArgs(void)
{ {
TEST_FAIL(); 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);
} }
@@ -20,7 +43,8 @@ void test_one(void)
int main(void) int main(void)
{ {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_one); RUN_TEST(test_configWithCorecctArgs);
RUN_TEST(test_configWithoutPointerToDisplay);
return UNITY_END(); return UNITY_END();
} }