Skip to content

Commit

Permalink
modified: code.c
Browse files Browse the repository at this point in the history
	modified:   conf.oil
	modified:   inc/esp8266_settings.h
	modified:   inc/http.h
	modified:   inc/network.h
	modified:   src/app.c
	modified:   src/esp8266_client.c
	modified:   src/esp8266_driver.c
	modified:   src/esp8266_link.c
	modified:   src/esp8266_netstat.c
	modified:   src/esp8266_server.c
	modified:   src/esp8266_settings.c
	modified:   src/json_parser.c
	modified:   src/network.c
	modified:   src/spotify.c
	modified:   src/ui.c
	modified:   ui/src/Touch.c
  • Loading branch information
ckevar committed Sep 13, 2024
1 parent 00695fd commit c04f49f
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 475 deletions.
Binary file modified c_mX.bin
Binary file not shown.
90 changes: 3 additions & 87 deletions code.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
/* ###*B*###
* ERIKA Enterprise - a tiny RTOS for small microcontrollers
*
* Copyright (C) 2002-2013 Evidence Srl
*
* This file is part of ERIKA Enterprise.
*
* ERIKA Enterprise is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation,
* (with a special exception described below).
*
* Linking this code statically or dynamically with other modules is
* making a combined work based on this code. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give you
* permission to link this code with independent modules to produce an
* executable, regardless of the license terms of these independent
* modules, and to copy and distribute the resulting executable under
* terms of your choice, provided that you also meet, for each linked
* independent module, the terms and conditions of the license of that
* module. An independent module is a module which is not derived from
* or based on this library. If you modify this code, you may extend
* this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* ERIKA Enterprise is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License version 2 for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with ERIKA Enterprise; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
* ###*E*### */

/*
* Simple demo that shows how to use the USART peripheral.
*
* Author: 2013 Gianluca Franchino.
*
*/


#include "ee.h"

#include "stm32f4xx.h"
Expand Down Expand Up @@ -102,11 +54,10 @@ TASK(LCD_IN) {
burst <<= 1;
}
TASK(ESP8266_POLL) {
if (esp8_status.cmd == ESP8_UNKNOWN) {
esp8266_poll();
}
STM_EVAL_LEDToggle(LED4);
if (esp8_status.cmd != ESP8_UNKNOWN)
return;

esp8266_poll();
}

TASK(NETWORK) {
Expand All @@ -121,41 +72,6 @@ TASK(SPOTIFY_UPDATE) {
spotify_update_player();
}

/*
* ESP8266 TRANSMITTER
*/
void __IRQ EE_CORTEX_MX_DMA2_STREAM6_ISR(void) {
if (DMA2->HISR & DMA_HISR_TCIF6) {
// If interruption is because transfer is completed
DMA2->HIFCR = DMA_HIFCR_CTCIF6; // Ack interruptions
} else if (DMA2->HISR & DMA_HISR_DMEIF6) {
// If interruption on Direct Mode went wrong
LCD_UsrLog("ERROR on sending\r\n");
DMA2->HIFCR = DMA_HIFCR_CDMEIF6; // Ack interruption
}
}

/*
* ESP8266 RECEIVER
*/
void __IRQ EE_CORTEX_MX_DMA2_STREAM1_ISR(void) {
// LCD_UsrLog("CR:%d\r\n", DMA2_Stream1->CR);
if (DMA2->LISR & DMA_LISR_TCIF1) { // Interruption if reception is
// completed.
DMA2->LIFCR = DMA_LIFCR_CTCIF1; // Ack interruptions
}
else if (DMA2->LISR & DMA_LISR_TEIF1) {
// If interruption on transfer went wrong
DMA2->LIFCR = DMA_LIFCR_CTEIF1; // Ack interruption
LCD_UsrLog("ERROR transfer\r\n");
}
else if (DMA2->LISR & DMA_LISR_DMEIF1) {
// If interruption on Direct Mode went wrong
DMA2->LIFCR = DMA_LIFCR_CDMEIF1; // Ack interruption
LCD_UsrLog("ERROR Direct Mode\r\n");
}
}

int main(void)
{
/*
Expand Down
31 changes: 21 additions & 10 deletions conf.oil
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ CPU mySystem {
/******* NETWORK FSM *******/
ALARM NETWORK_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = NETWORK;};
ACTION = ACTIVATETASK {
TASK = NETWORK;
};
};

TASK NETWORK {
PRIORITY = 0x02; /* Low priority */
PRIORITY = 0x02; /* High priority */
AUTOSTART = FALSE;
STACK = SHARED;
ACTIVATION = 1; /* only one pending activation */
Expand All @@ -122,7 +124,9 @@ CPU mySystem {
/******* Interface for the ESP8266 *******/
ALARM ESP8266_POLL_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = ESP8266_POLL; };
ACTION = ACTIVATETASK {
TASK = ESP8266_POLL;
};
};

TASK ESP8266_POLL {
Expand All @@ -136,11 +140,13 @@ CPU mySystem {
/******* Touch *******/
ALARM LCD_IN_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = LCD_IN; };
ACTION = ACTIVATETASK {
TASK = LCD_IN;
};
};

TASK LCD_IN {
PRIORITY = 0x03; /* Low priority */
PRIORITY = 0x03; /* High priority */
AUTOSTART = FALSE;
STACK = SHARED;
ACTIVATION = 1; /* only one pending activation */
Expand All @@ -150,11 +156,13 @@ CPU mySystem {
/******* Weather *******/
ALARM WEATHER_UPDATE_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = WEATHER_UPDATE; };
ACTION = ACTIVATETASK {
TASK = WEATHER_UPDATE;
};
};

TASK WEATHER_UPDATE {
PRIORITY = 0x01;
PRIORITY = 0x01; /* Low Priority */
AUTOSTART = FALSE;
STACK = SHARED;
ACTIVATION = 1;
Expand All @@ -164,17 +172,20 @@ CPU mySystem {
/******* Spotify *******/
ALARM SPOTIFY_UPDATE_ALARM {
COUNTER = myCounter;
ACTION = ACTIVATETASK { TASK = SPOTIFY_UPDATE; };
ACTION = ACTIVATETASK {
TASK = SPOTIFY_UPDATE;
};
};

TASK SPOTIFY_UPDATE {
PRIORITY = 0x02;
PRIORITY = 0x02; /* Mediuem Priority */
AUTOSTART = FALSE;
STACK = SHARED;
ACTIVATION = 1;
SCHEDULE = FULL;
};


/* Interruption Handlers */
ISR systick_handler {
CATEGORY = 2;
ENTRY = "SYSTICK";
Expand Down
8 changes: 4 additions & 4 deletions inc/esp8266_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ typedef struct SSIDnPSWD_t {
uint8_t size;
} SSIDnPSWD_t;

uint16_t LUT_OK_powerup(enum ESP8InitialSetup prev_state);
uint16_t LUT_timeout_powerup(enum ESP8InitialSetup prev_subs);
uint16_t LUT_on_err_powerup(enum ESP8InitialSetup prev_subs);
void fsm_powerup(struct StateS *state);
uint16_t LUT_OK_initial_setup(enum ESP8InitialSetup prev_state);
uint16_t LUT_timeout_initial_setup(enum ESP8InitialSetup prev_subs);
uint16_t LUT_on_err_initial_setup(enum ESP8InitialSetup prev_subs);
void fsm_initial_setup(struct StateS *state);

uint16_t LUT_OK_access_point(enum ESP8AccessPointState prev_subs);
void fsm_ap_config(struct StateS *state);
Expand Down
2 changes: 1 addition & 1 deletion inc/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum HTTPStatusCode {
HTTP_401 = '4' << 8 | 1,
HTTP_500 = '5' << 8,
HTTP_520 = '5' << 8 | 2 << 4,
HTTP_522 = '5' << 8 | 2 << 2 | 2,
HTTP_522 = '5' << 8 | 2 << 4 | 2,
};

struct outHTTP {
Expand Down
2 changes: 1 addition & 1 deletion inc/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "net_credentials_conf.h"

enum ESP8NetManagerState {
ESP8SS_POWER_UP,
ESP8SS_INIT,
ESP8SS_INITIAL_SETUP,
ESP8SS_NETSTATUS,
ESP8SS_AP,
Expand Down
46 changes: 23 additions & 23 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "WidgetConfig.h"

#define MATCH(str, res) if(memcmp(str, res, res##_LEN) == 0)
#define MATCH(str, res) if(0 == memcmp(str, res, res##_LEN))

#define SPOTIFY_UPDATE_EVENT 0b001
#define WEATHER_UPDATE_EVENT 0b010
Expand Down Expand Up @@ -73,7 +73,7 @@ static void app_spotify_conf(uint8_t *success, char *http, void *arg) {
MATCH(http, SPOTY_REQ) {
memset(http, 0, SPOTY_REQ_LEN);

if(spotify_on_root(&out, ESP8266_IPv4.ip) == 0) {
if(0 == spotify_on_root(&out, ESP8266_IPv4.ip)) {
*success = 0;
return;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ void app_http_from_WebApp(uint8_t *success, char *http, void *arg) {
// Iterate until
while(http[i] != '&') {
// Replacing '+'s by ' ' (spaces)
snp->ssidNpassword[snp->size] = (http[i] == '+') \
snp->ssidNpassword[snp->size] = ('+' == http[i]) \
? ' '\
: http[i];
snp->size++;
Expand Down Expand Up @@ -286,7 +286,7 @@ static void spotify_track_processor(uint8_t *success, char *json, void *arg) {
uint16_t sizes[SPOTIFY_TRACK_COUNT];
char track_info[TRACK_INFO_SIZE];

if (esp8_status.http == HTTP_204) {
if (HTTP_204 == esp8_status.http) {
*success = 0;
UI_set_track("Spotify Player off");
return;
Expand Down Expand Up @@ -354,7 +354,7 @@ void server_function(struct StateS *s, enum ServersID _server_id) {
// case SERVER_RUNNING:
fsm_server(s, &socket);

if (wifi_credentials.size > 0 && SUBSTATE(*s->state) == ESP8S_LISTENING)
if ((wifi_credentials.size > 0) && (ESP8S_LISTENING == SUBSTATE(*s->state)))
fsm_station_credentials(s, &wifi_credentials);

break;
Expand All @@ -381,15 +381,15 @@ void server_function(struct StateS *s, enum ServersID _server_id) {
// case SERVER_RUNNING:
fsm_server(s, &socket);

if(*(spotify_auth_content + SPOTIFY_AUTH_RANDOM_POS) > SPOTIFY_AUTH_NON_EMPTY && \
SUBSTATE(*s->state) == ESP8S_LISTENING)
if((spotify_auth_content[SPOTIFY_AUTH_RANDOM_POS] > SPOTIFY_AUTH_NON_EMPTY) && \
(ESP8S_LISTENING == SUBSTATE(*s->state)))
{
*s->nx_state = MKSTATE(ESP8SS_INITIAL_SETUP, ESP8S_RESTART);
}

}

if (SUBSTATE(*s->state) == ESP8S_SERVER_OFF)
if (ESP8S_SERVER_OFF == SUBSTATE(*s->state))
server_state = SERVER_CONF;

}
Expand Down Expand Up @@ -446,7 +446,7 @@ void client_function(struct StateS *state, uint8_t *_client_id) {
case CLIENT_EXEC:
fsm_client(state, &sock);

if (SUPERSTATE(*state->nx_state) == ESP8SS_READY) {
if (ESP8SS_READY == SUPERSTATE(*state->nx_state)) {
client_state = CLIENT_CONF;
client_id = WEATHER;
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_TCP);
Expand All @@ -471,8 +471,8 @@ void client_function(struct StateS *state, uint8_t *_client_id) {
case CLIENT_EXEC:
fsm_client(state, &sock);

if(SUPERSTATE(*state->nx_state) == ESP8SS_READY
|| esp8_status.http == HTTP_401)
if((ESP8SS_READY == SUPERSTATE(*state->nx_state)) ||
(HTTP_401 == esp8_status.http))
{
if (*spotify_token > ' ') {
client_id = SPOTIFY_PLAYER;
Expand Down Expand Up @@ -528,7 +528,7 @@ void client_function(struct StateS *state, uint8_t *_client_id) {
client_state = CLIENT_EXEC;

case CLIENT_EXEC:
if (SUBSTATE(*state->nx_state) == ESP8S_CONNECT_TCP)
if (ESP8S_CONNECT_TCP == SUBSTATE(*state->nx_state))
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);

if (esp8_status.http > HTTP_500) {
Expand All @@ -538,7 +538,7 @@ void client_function(struct StateS *state, uint8_t *_client_id) {

fsm_client(state, &sock);

if(SUPERSTATE(*state->nx_state) == ESP8SS_READY) {
if(ESP8SS_READY == SUPERSTATE(*state->nx_state)) {
client_state = CLIENT_CONF;
if (*spotify_token > ' ') {
client_id = SPOTIFY_PLAYER;
Expand Down Expand Up @@ -582,7 +582,7 @@ void client_function(struct StateS *state, uint8_t *_client_id) {
client_state = CLIENT_EXEC;

case CLIENT_EXEC:
if(SUBSTATE(*state->nx_state) == ESP8S_CONNECT_TCP)
if(ESP8S_CONNECT_TCP == SUBSTATE(*state->nx_state))
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);

if(esp8_status.http > HTTP_500) {
Expand All @@ -592,7 +592,7 @@ void client_function(struct StateS *state, uint8_t *_client_id) {

fsm_client(state, &sock);

if (esp8_status.http == HTTP_401) {
if (HTTP_401 == esp8_status.http) {
client_state = CLIENT_CONF;
// When the Token is expired a renewal is asked
// using the refreshing token.
Expand All @@ -612,8 +612,8 @@ void client_function(struct StateS *state, uint8_t *_client_id) {
client_id = SPOTIFY_AUTH;
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_SSL);
}
else if (esp8_status.http == HTTP_200 || esp8_status.http == HTTP_204) {
if(SUBSTATE(*state->nx_state) == ESP8S_CLOSE) {
else if ((HTTP_200 == esp8_status.http) || (HTTP_204 == esp8_status.http)) {
if(ESP8S_CLOSE == SUBSTATE(*state->nx_state)) {
*state->nx_state = MKSTATE(ESP8SS_READY, 0);
}
}
Expand Down Expand Up @@ -644,11 +644,11 @@ NetEventHandler(struct StateS *s, uint8_t *server_id, uint8_t * client_id)
return;
}

if ((internal_events) &&\
(SUPERSTATE(*s->state) != ESP8SS_AP) &&\
(SUPERSTATE(*s->state) != ESP8SS_SERVER) &&\
(SUPERSTATE(*s->state) != ESP8SS_STATION_CREDENTIALS) &&\
(SUPERSTATE(*s->nx_state) == ESP8SS_READY))
if ((internal_events) &&
(SUPERSTATE(*s->state) != ESP8SS_AP) &&
(SUPERSTATE(*s->state) != ESP8SS_SERVER) &&
(SUPERSTATE(*s->state) != ESP8SS_STATION_CREDENTIALS) &&
(ESP8SS_READY == SUPERSTATE(*s->nx_state)))
{
if (internal_events & WEATHER_UPDATE_EVENT_CORE) {
internal_events &= ~WEATHER_UPDATE_EVENT_CORE;
Expand All @@ -663,7 +663,7 @@ NetEventHandler(struct StateS *s, uint8_t *server_id, uint8_t * client_id)
internal_events = WEATHER_UPDATE_EVENT_CORE;

} else if(internal_events & SPOTIFY_UPDATE_EVENT) {
if(*spotify_auth_content == SPOTIFY_AUTH_EMPTY)
if(SPOTIFY_AUTH_EMPTY == *spotify_auth_content)
return;

internal_events &= ~SPOTIFY_UPDATE_EVENT;
Expand Down
4 changes: 2 additions & 2 deletions src/esp8266_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ uint16_t LUT_OK_client(enum ESP8Client prev_subs) {
[ESP8S_CLOSE] = MKSTATE(ESP8SS_CLIENT, ESP8S_DONE),
};

if (prev_subs > ESP8_CLIENT_COUNT)
if (prev_subs >= ESP8_CLIENT_COUNT)
return MKSTATE(ESP8SS_INITIAL_SETUP, ESP8S_RESTART);

return LUT[prev_subs];
Expand Down Expand Up @@ -61,7 +61,7 @@ void fsm_client(struct StateS *state, struct Socket *so) {
break;

case ESP8S_CREAD:
if (app_http_process(ESP8SS_CLIENT, so->callback, so->arg) == 0)
if (0 == app_http_process(ESP8SS_CLIENT, so->callback, so->arg))
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CLOSE);
else
*state->nx_state = MKSTATE(ESP8SS_CLIENT, ESP8S_CONNECT_TCP);
Expand Down
Loading

0 comments on commit c04f49f

Please sign in to comment.