4 Commits

4 changed files with 63 additions and 64 deletions

View File

@@ -37,7 +37,8 @@
* If the pointer is invalid, the function using this macro will return with * If the pointer is invalid, the function using this macro will return with
* CONFIG_PARSER_PARAM_ERR * CONFIG_PARSER_PARAM_ERR
*/ */
#define config_parser_check_handle(handle) do { if (!(handle) || \ #define config_parser_check_handle(handle) do { \
if (!(handle) || \
((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \ ((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \
return CONFIG_PARSER_PARAM_ERR; \ return CONFIG_PARSER_PARAM_ERR; \
} while (0) } while (0)
@@ -92,17 +93,17 @@ static int parse_value(struct config_parser_entry *entry, char *value_start_toke
if (value_start_token[0] != '-') { if (value_start_token[0] != '-') {
/* Try parsing as ul */ /* Try parsing as ul */
entry->value.uint_val = strtoul(value_start_token, &endptr, 0); entry->value.uint_val = strtoul(value_start_token, &endptr, 0);
if (endptr == value_start_token) { if (endptr == value_start_token)
return -1; return -1;
}
entry->type = CONFIG_PARSER_TYPE_UINT; entry->type = CONFIG_PARSER_TYPE_UINT;
goto exit; goto exit;
} else { } else {
/* Try parsing as int */ /* Try parsing as int */
entry->value.int_val = strtod(value_start_token, &endptr); entry->value.int_val = strtod(value_start_token, &endptr);
if (endptr == value_start_token) { if (endptr == value_start_token)
return -1; return -1;
}
entry->type = CONFIG_PARSER_TYPE_INT; entry->type = CONFIG_PARSER_TYPE_INT;
} }
@@ -110,14 +111,16 @@ exit:
return 0; return 0;
} }
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry, bool force_float) enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry,
bool force_float)
{ {
struct config_parser *p; struct config_parser *p;
config_parser_check_handle(handle);
p = CONFIG_PARSER(handle);
char *token; char *token;
int token_round = 0; int token_round = 0;
config_parser_check_handle(handle);
p = CONFIG_PARSER(handle);
if (!entry) if (!entry)
return CONFIG_PARSER_PARAM_ERR; return CONFIG_PARSER_PARAM_ERR;
@@ -131,7 +134,6 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str
if (token[0] == '#') { if (token[0] == '#') {
if (token_round == 0) if (token_round == 0)
return CONFIG_PARSER_LINE_COMMENT; return CONFIG_PARSER_LINE_COMMENT;
else
break; break;
} }
@@ -140,9 +142,8 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str
entry->name = token; entry->name = token;
break; break;
case 1: /* = Symbol */ case 1: /* = Symbol */
if (strcmp(token, "=")) { if (strcmp(token, "="))
return CONFIG_PARSER_LINE_MALFORM; return CONFIG_PARSER_LINE_MALFORM;
}
break; break;
case 2: /* VALUE */ case 2: /* VALUE */
if (parse_value(entry, token)) if (parse_value(entry, token))
@@ -172,6 +173,7 @@ enum config_parser_ret config_parser_reset_to_start(config_parser_handle_t handl
{ {
FRESULT res; FRESULT res;
struct config_parser *p; struct config_parser *p;
config_parser_check_handle(handle); config_parser_check_handle(handle);
p = CONFIG_PARSER(handle); p = CONFIG_PARSER(handle);
@@ -194,6 +196,7 @@ enum config_parser_ret config_parser_close_file(config_parser_handle_t handle)
{ {
struct config_parser *p; struct config_parser *p;
FRESULT res; FRESULT res;
config_parser_check_handle(handle); config_parser_check_handle(handle);
p = CONFIG_PARSER(handle); p = CONFIG_PARSER(handle);

View File

@@ -28,12 +28,12 @@
* @brief Initialize the SPI for the eeprom. * @brief Initialize the SPI for the eeprom.
* @return 0 if succesful * @return 0 if succesful
*/ */
int spi_eeprom_init(); int spi_eeprom_init(void);
/** /**
* @brief Uninitialize the SPI EEPROM * @brief Uninitialize the SPI EEPROM
*/ */
void spi_eeprom_deinit(); void spi_eeprom_deinit(void);
/** /**
* @brief Read from SPI EEPROM * @brief Read from SPI EEPROM

View File

@@ -1,22 +1,22 @@
/* Reflow Oven Controller /* Reflow Oven Controller
* *
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net> * Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
* *
* This file is part of the Reflow Oven Controller Project. * This file is part of the Reflow Oven Controller Project.
* *
* The reflow oven controller is free software: you can redistribute it and/or modify * The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, * The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the reflow oven controller project. * along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <reflow-controller/settings/settings-sd-card.h> #include <reflow-controller/settings/settings-sd-card.h>
#include <stm-periph/unique-id.h> #include <stm-periph/unique-id.h>
@@ -72,18 +72,12 @@ static int create_controller_folder(void)
ret = 0; ret = 0;
} else { } else {
filesystem_result = f_mkdir(foldername); filesystem_result = f_mkdir(foldername);
if (filesystem_result == FR_OK) { ret = filesystem_result == FR_OK ? 1 : -1;
ret = 1;
} else {
ret = -1;
}
} }
return ret; return ret;
} }
int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active) int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active)
{ {
char path[200]; char path[200];

View File

@@ -1,22 +1,22 @@
/* Reflow Oven Controller /* Reflow Oven Controller
* *
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net> * Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
* *
* This file is part of the Reflow Oven Controller Project. * This file is part of the Reflow Oven Controller Project.
* *
* The reflow oven controller is free software: you can redistribute it and/or modify * The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful, * The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the reflow oven controller project. * along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <reflow-controller/settings/spi-eeprom.h> #include <reflow-controller/settings/spi-eeprom.h>
#include <stm-periph/spi.h> #include <stm-periph/spi.h>
@@ -52,7 +52,7 @@ static void eeprom_cs_deactivate(void)
SPI_EEPROM_SPI_PORT->ODR |= (1<<SPI_EEPROM_CS_PIN); SPI_EEPROM_SPI_PORT->ODR |= (1<<SPI_EEPROM_CS_PIN);
} }
int spi_eeprom_init() int spi_eeprom_init(void)
{ {
static struct stm_spi_dev spi_dev; static struct stm_spi_dev spi_dev;
struct stm_spi_settings settings; struct stm_spi_settings settings;
@@ -61,7 +61,8 @@ int spi_eeprom_init()
SPI_EEPROM_SPI_PORT->MODER &= MODER_DELETE(SPI_EEPROM_CS_PIN) & MODER_DELETE(SPI_EEPROM_MISO_PIN) & SPI_EEPROM_SPI_PORT->MODER &= MODER_DELETE(SPI_EEPROM_CS_PIN) & MODER_DELETE(SPI_EEPROM_MISO_PIN) &
MODER_DELETE(SPI_EEPROM_MOSI_PIN) & MODER_DELETE(SPI_EEPROM_SCK_PIN); MODER_DELETE(SPI_EEPROM_MOSI_PIN) & MODER_DELETE(SPI_EEPROM_SCK_PIN);
SPI_EEPROM_SPI_PORT->MODER |= ALTFUNC(SPI_EEPROM_MISO_PIN) | ALTFUNC(SPI_EEPROM_SCK_PIN) | ALTFUNC(SPI_EEPROM_MOSI_PIN); SPI_EEPROM_SPI_PORT->MODER |= ALTFUNC(SPI_EEPROM_MISO_PIN) | ALTFUNC(SPI_EEPROM_SCK_PIN) |
ALTFUNC(SPI_EEPROM_MOSI_PIN);
SPI_EEPROM_SPI_PORT->MODER |= OUTPUT(SPI_EEPROM_CS_PIN); SPI_EEPROM_SPI_PORT->MODER |= OUTPUT(SPI_EEPROM_CS_PIN);
SETAF(SPI_EEPROM_SPI_PORT, SPI_EEPROM_MISO_PIN, SPI_EEPROM_SPI_ALTFUNC_NO); SETAF(SPI_EEPROM_SPI_PORT, SPI_EEPROM_MISO_PIN, SPI_EEPROM_SPI_ALTFUNC_NO);
@@ -85,7 +86,7 @@ int spi_eeprom_init()
return -1; return -1;
} }
void spi_eeprom_deinit() void spi_eeprom_deinit(void)
{ {
spi_deinit(eeprom_spi_handle); spi_deinit(eeprom_spi_handle);
@@ -166,7 +167,8 @@ static void spi_eeprom_do_write_page(uint32_t addr, const uint8_t *data, uint8_t
uint8_t cmd[2]; uint8_t cmd[2];
/* Wait for the previous write to finish */ /* Wait for the previous write to finish */
while (spi_eeprom_write_in_progress()); while (spi_eeprom_write_in_progress())
;
/* Set the write enable latch */ /* Set the write enable latch */
spi_eeprom_set_write_enable_latch(true); spi_eeprom_set_write_enable_latch(true);