Compare commits
	
		
			3 Commits
		
	
	
		
			6b8b8c3314
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 3fa55b8fa2 | |||
| 9a6d82fb64 | |||
| e6eb45dd9b | 
@@ -33,7 +33,7 @@ extern "C"
 | 
				
			|||||||
    typedef struct // Structure for initial initialization of PCF8574 expander.
 | 
					    typedef struct // Structure for initial initialization of PCF8574 expander.
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        uint8_t task_priority;  // Task priority for the PCF8574 expander isr processing. @note It is not recommended to set a value less than configMAX_PRIORITIES.
 | 
					        uint8_t task_priority;  // Task priority for the PCF8574 expander isr processing. @note It is not recommended to set a value less than configMAX_PRIORITIES.
 | 
				
			||||||
        uint8_t stack_size;     // Stack size for task for the PCF8574 expander isr processing processing. @note The minimum size is 124 byte.
 | 
					        uint8_t stack_size;     // Stack size for task for the PCF8574 expander isr processing processing.
 | 
				
			||||||
        uint8_t i2c_address;    // Expander I2C address.
 | 
					        uint8_t i2c_address;    // Expander I2C address.
 | 
				
			||||||
        bool p0_gpio_work_mode; // Expander GPIO PO work mode. True for input, false for output.
 | 
					        bool p0_gpio_work_mode; // Expander GPIO PO work mode. True for input, false for output.
 | 
				
			||||||
        bool p1_gpio_work_mode; // Expander GPIO P1 work mode. True for input, false for output.
 | 
					        bool p1_gpio_work_mode; // Expander GPIO P1 work mode. True for input, false for output.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +1 @@
 | 
				
			|||||||
1.3.0
 | 
					1.3.2
 | 
				
			||||||
@@ -1,9 +1,11 @@
 | 
				
			|||||||
#include "zh_avr_pcf8574.h"
 | 
					#include "zh_avr_pcf8574.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TaskHandle_t zh_avr_pcf8574 = NULL;
 | 
				
			||||||
static uint8_t _interrupt_gpio = 0xFF;
 | 
					static uint8_t _interrupt_gpio = 0xFF;
 | 
				
			||||||
static uint8_t _interrupt_port = 0;
 | 
					static uint8_t _interrupt_port = 0;
 | 
				
			||||||
static SemaphoreHandle_t _interrupt_semaphore = NULL;
 | 
					static SemaphoreHandle_t _interrupt_semaphore = NULL;
 | 
				
			||||||
static const uint8_t _gpio_matrix[8] PROGMEM = {AVR_BIT0, AVR_BIT1, AVR_BIT2, AVR_BIT3, AVR_BIT4, AVR_BIT5, AVR_BIT6, AVR_BIT7};
 | 
					static const uint8_t _gpio_matrix[8] PROGMEM = {AVR_BIT0, AVR_BIT1, AVR_BIT2, AVR_BIT3, AVR_BIT4, AVR_BIT5, AVR_BIT6, AVR_BIT7};
 | 
				
			||||||
 | 
					volatile static bool _interrupt_on = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static zh_avr_vector_t _vector = {0};
 | 
					static zh_avr_vector_t _vector = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -81,7 +83,7 @@ static avr_err_t _zh_avr_pcf8574_validate_config(const zh_avr_pcf8574_init_confi
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    ZH_ERROR_CHECK(config != NULL, AVR_ERR_INVALID_ARG);
 | 
					    ZH_ERROR_CHECK(config != NULL, AVR_ERR_INVALID_ARG);
 | 
				
			||||||
    ZH_ERROR_CHECK((config->i2c_address >= 0x20 && config->i2c_address <= 0x27) || (config->i2c_address >= 0x38 && config->i2c_address <= 0x3F), AVR_ERR_INVALID_ARG);
 | 
					    ZH_ERROR_CHECK((config->i2c_address >= 0x20 && config->i2c_address <= 0x27) || (config->i2c_address >= 0x38 && config->i2c_address <= 0x3F), AVR_ERR_INVALID_ARG);
 | 
				
			||||||
    ZH_ERROR_CHECK(config->task_priority > tskIDLE_PRIORITY && config->stack_size >= 124, AVR_ERR_INVALID_ARG);
 | 
					    ZH_ERROR_CHECK(config->task_priority > tskIDLE_PRIORITY && config->stack_size >= configMINIMAL_STACK_SIZE, AVR_ERR_INVALID_ARG);
 | 
				
			||||||
    ZH_ERROR_CHECK(config->interrupt_gpio == 0xFF || (config->interrupt_gpio >= 0 && config->interrupt_gpio <= 7), AVR_ERR_INVALID_ARG);
 | 
					    ZH_ERROR_CHECK(config->interrupt_gpio == 0xFF || (config->interrupt_gpio >= 0 && config->interrupt_gpio <= 7), AVR_ERR_INVALID_ARG);
 | 
				
			||||||
    if (config->interrupt_gpio != 0xFF)
 | 
					    if (config->interrupt_gpio != 0xFF)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -145,7 +147,7 @@ static avr_err_t _zh_avr_pcf8574_configure_interrupts(const zh_avr_pcf8574_init_
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    _interrupt_semaphore = xSemaphoreCreateBinary();
 | 
					    _interrupt_semaphore = xSemaphoreCreateBinary();
 | 
				
			||||||
    ZH_ERROR_CHECK(_interrupt_semaphore != NULL, AVR_ERR_NO_MEM);
 | 
					    ZH_ERROR_CHECK(_interrupt_semaphore != NULL, AVR_ERR_NO_MEM);
 | 
				
			||||||
    BaseType_t x_err = xTaskCreate(_zh_avr_pcf8574_isr_processing_task, NULL, config->stack_size, NULL, config->task_priority, NULL);
 | 
					    BaseType_t x_err = xTaskCreate(_zh_avr_pcf8574_isr_processing_task, "zh_avr_pcf8574", config->stack_size, NULL, config->task_priority, &zh_avr_pcf8574);
 | 
				
			||||||
    if (x_err != pdPASS)
 | 
					    if (x_err != pdPASS)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        vSemaphoreDelete(_interrupt_semaphore);
 | 
					        vSemaphoreDelete(_interrupt_semaphore);
 | 
				
			||||||
@@ -160,23 +162,62 @@ BaseType_t zh_avr_pcf8574_isr_handler(void)
 | 
				
			|||||||
    switch (_interrupt_port)
 | 
					    switch (_interrupt_port)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    case AVR_PORTB:
 | 
					    case AVR_PORTB:
 | 
				
			||||||
 | 
					        if ((PINB & (1 << _interrupt_gpio)) == (1 << _interrupt_gpio))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == false)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if ((PINB & (1 << _interrupt_gpio)) == 0)
 | 
					        if ((PINB & (1 << _interrupt_gpio)) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == true)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = false;
 | 
				
			||||||
                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
					                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    case AVR_PORTC:
 | 
					    case AVR_PORTC:
 | 
				
			||||||
 | 
					        if ((PINC & (1 << _interrupt_gpio)) == (1 << _interrupt_gpio))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == false)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if ((PINC & (1 << _interrupt_gpio)) == 0)
 | 
					        if ((PINC & (1 << _interrupt_gpio)) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == true)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = false;
 | 
				
			||||||
                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
					                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    case AVR_PORTD:
 | 
					    case AVR_PORTD:
 | 
				
			||||||
 | 
					        if ((PIND & (1 << _interrupt_gpio)) == (1 << _interrupt_gpio))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == false)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        if ((PIND & (1 << _interrupt_gpio)) == 0)
 | 
					        if ((PIND & (1 << _interrupt_gpio)) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            if (_interrupt_on == true)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _interrupt_on = false;
 | 
				
			||||||
                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
					                xSemaphoreGiveFromISR(_interrupt_semaphore, &xHigherPriorityTaskWoken);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user