//////////////////////////////////////////////////////////////////
//
// App:			Ports Controller Task
// Author:		Milan Korinek
// Version:		1.0
// Notice:		Control of I/O expander
//////////////////////////////////////////////////////////////////


#ifndef PORTS_CONTROLLER_H_
#define PORTS_CONTROLLER_H_

#include <config_tasks.h>
#include "support/support.h"
#include "support/TWI_IO_Expander.h"

#define MAX_WAIT_TO_SET_PORTS (200UL / portTICK_RATE_MS)

/* Messages types with auto generate string names */
#define FOREACH_ports_controller_msg_type(ITEM) \
ITEM(PORTS_CNTR_MSG_LED_SET)   \
ITEM(PORTS_CNTR_MSG_PWR_SET)  \
ITEM(PORTS_CNTR_MSG_DIR_SET)   \
ITEM(PORTS_CNTR_MSG_PULL_RES_SET)  \
ITEM(PORTS_CNTR_MSG_FAULT_GET)  \

typedef enum {
	FOREACH_ports_controller_msg_type(GENERATE_ENUM)
} ports_controller_msg_type_t;

extern const char *const ports_controller_msg_type_str_t[];

typedef struct {
	ports_controller_msg_type_t message;
	uint32_t devices;
	uint32_t enable;
	uint32_t settings;	
} ports_controller_msg_t;

typedef struct {
	xTaskHandle task_handle;
	xQueueHandle control_pipe;
} ports_controller_handle_t;

status_code_t ports_controller_init(ports_controller_handle_t * task_handle);

void ports_controller_task(void *pvParameters);

#endif /* PORTS_CONTROLLER_H_ */