First version that compiles with new file layout.

Had to make many changes to get it to compile across many files,
including removing the LOCAL specifier from almost all functions.
Edited the Makefile to compile all three files and link them.
Haven't tested on hardware yet, that's the next step.

Lots of small changes to avoid warnings, now that I have turned
-Wall on. This makes the code a bit "better".

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
This commit is contained in:
A.M. Rowsell 2019-01-20 21:13:04 -05:00
commit 48702bf328
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
7 changed files with 124 additions and 72 deletions

View file

@ -1,38 +1,73 @@
#include <stdint.h>
#include "os_type.h"
#include "osapi.h"
#include "user_interface.h"
#include "gpio.h"
#include "hw_timer.c"
#include "onewire.h"
LOCAL void timerISR(void) {
return;
}
LOCAL void reset(oneWire_t *owDev) {
sint8 ICACHE_FLASH_ATTR init(oneWire_t *owDev) {
uint32_t time;
// reset the ow line, check for presence?
time = system_get_time() + 500;
gpio_output_set(0, BIT4, BIT4, 0); // pull GPIO4 low
while(system_get_time() < time); // delay 500uS
gpio_output_set(0, 0, 0, BIT4); // let go of GPIO4
time = system_get_time() + 60;
while(system_get_time() < time);
uint8_t presence = (uint8_t)(gpio_input_get() >> 4) & 0x1;
if(presence) {
return 1;
} else {
return -1;
}
}
LOCAL void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) {
switch(cmd) {
case READ_ROM:
break;
case MATCH_ROM:
break;
case SEARCH_ROM:
break;
case ALARM_SEARCH:
break;
case SKIP_ROM:
break;
case CONVERT_T:
break;
case SCRATCH_READ:
break;
case SCRATCH_WRITE:
break;
case SCRATCH_COPY:
break;
case E2_RECALL:
break;
void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) {
uint32_t time;
uint8_t sendBit;
uint8_t inBit = 0x00;
uint8_t inByte = 0x00;
if((cmd == SKIP_ROM) | (cmd == CONVERT_T)) {
for(uint8_t i = 7; i >= 0; i--) {
sendBit = (cmd >> i) & 0x1;
if(sendBit == 1) {
time = system_get_time() + 10;
gpio_output_set(0, BIT4, BIT4, 0); // pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, BIT4); // let go
} else {
time = system_get_time() + 100;
gpio_output_set(0, BIT4, BIT4, 0); //pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, BIT4);
}
}
} else if(cmd == SCRATCH_READ) {
for(uint8_t i = 7; i >= 0; i--) {
sendBit = (cmd >> i) & 0x1;
if(sendBit == 1) {
time = system_get_time() + 10;
gpio_output_set(0, BIT4, BIT4, 0); // pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, BIT4); // let go
} else {
time = system_get_time() + 100;
gpio_output_set(0, BIT4, BIT4, 0); //pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, BIT4);
}
}
// now read the scratchpad
for(uint8_t i = 0; i < 2; i++) {
for(uint8_t j = 0; j < 8; j++) {
time = system_get_time() + 8;
gpio_output_set(0, BIT4, BIT4, 0);
while(system_get_time() < time);
gpio_output_set(0, 0, 0, BIT4);
inBit = (uint8_t)(gpio_input_get() >> 4) & 0x01;
inByte |= inBit << j;
}
owDev->scratchpad[i] = inByte;
}
}
}