@@ -87,20 +87,20 @@ static volatile uint8_t twi_rxBufferIndex;
87
87
static void (* twi_onSlaveTransmit )(void );
88
88
static void (* twi_onSlaveReceive )(uint8_t * , int );
89
89
90
- void onSclChange (void );
91
- void onSdaChange (void );
90
+ static void onSclChange (void );
91
+ static void onSdaChange (void );
92
92
93
- #define TASK_QUEUE_SIZE 1
94
- #define TASK_QUEUE_PRIO 2
93
+ #define EVENTTASK_QUEUE_SIZE 1
94
+ #define EVENTTASK_QUEUE_PRIO 2
95
95
96
96
#define TWI_SIG_RANGE 0x00000100
97
97
#define TWI_SIG_RX (TWI_SIG_RANGE + 0x01)
98
98
#define TWI_SIG_TX (TWI_SIG_RANGE + 0x02)
99
99
100
- static ETSEvent task_queue [ TASK_QUEUE_SIZE ];
101
- static void task (ETSEvent * e );
100
+ static ETSEvent eventTaskQueue [ EVENTTASK_QUEUE_SIZE ];
101
+ static void eventTask (ETSEvent * e );
102
102
static ETSTimer timer ;
103
- void onTimer (void * timer_arg );
103
+ static void onTimer (void * timer_arg );
104
104
105
105
#define SDA_LOW () (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
106
106
#define SDA_HIGH () (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
@@ -141,15 +141,13 @@ void twi_setClockStretchLimit(uint32_t limit){
141
141
twi_clockStretchLimit = limit * TWI_CLOCK_STRETCH_MULTIPLIER ;
142
142
}
143
143
144
- void twi_init (unsigned char sda , unsigned char scl ){
145
-
146
-
147
- ets_timer_setfn (& timer , onTimer , NULL );
148
-
149
- ets_task (task , TASK_QUEUE_PRIO , task_queue , TASK_QUEUE_SIZE );
150
-
151
- ets_post (TASK_QUEUE_PRIO , 9 , 42 );
152
-
144
+ void twi_init (unsigned char sda , unsigned char scl )
145
+ {
146
+ // set timer function
147
+ ets_timer_setfn (& timer , onTimer , NULL );
148
+
149
+ // create event task
150
+ ets_task (eventTask , EVENTTASK_QUEUE_PRIO , eventTaskQueue , EVENTTASK_QUEUE_SIZE );
153
151
154
152
twi_sda = sda ;
155
153
twi_scl = scl ;
@@ -409,7 +407,7 @@ void ICACHE_RAM_ATTR onTimer(void *timer_arg)
409
407
digitalWrite (13 , LOW );
410
408
}
411
409
412
- static void task (ETSEvent * e )
410
+ static void eventTask (ETSEvent * e )
413
411
{
414
412
digitalWrite (14 , HIGH );
415
413
@@ -555,7 +553,7 @@ void ICACHE_RAM_ATTR twi_onTwipEvent(uint8_t status)
555
553
// callback to user defined callback
556
554
//twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
557
555
//twi_rxBufferLock = true; // This may be necessary
558
- ets_post (TASK_QUEUE_PRIO , TWI_SIG_RX , twi_rxBufferIndex );
556
+ ets_post (EVENTTASK_QUEUE_PRIO , TWI_SIG_RX , twi_rxBufferIndex );
559
557
560
558
// since we submit rx buffer to "wire" library, we can reset it
561
559
twi_rxBufferIndex = 0 ;
0 commit comments