Skip to content

Commit

Permalink
Merge pull request #49 from DAT540/main
Browse files Browse the repository at this point in the history
Tibbit #62 library with the ability to automatically update the firmware.
  • Loading branch information
salhk authored Dec 17, 2024
2 parents 0e1b257 + c730500 commit 6033aa7
Show file tree
Hide file tree
Showing 7 changed files with 1,492 additions and 58 deletions.
10 changes: 1 addition & 9 deletions pic/PIC_LVP.tbh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef PIC_LVP_MAX_DATA_LEN
#define PIC_LVP_MAX_DATA_LEN 8192
#endif
Expand All @@ -23,12 +22,6 @@
#define PIC_LVP_DEBUG_PRINT 1
#endif

' You must define this define in your code with the type of the PIC processor that needs to be flashed.
' See enum PIC_TYPE
#ifndef PIC_LVP_TARGET_TYPE
#define PIC_LVP_TARGET_TYPE 0 ' Unknown PIC type
#endif

' PIC TYPE
enum PIC_TYPE
PIC_16F1826 = &b10011110000000,
Expand Down Expand Up @@ -89,7 +82,6 @@ enum PIC_TYPE
PIC_16LF18456 = &h30DA
end enum

declare sub pic_lvp_start(SCL as byte, SDA as byte, MCLR as byte)
declare sub pic_lvp_start(target as PIC_TYPE, SCL as byte, SDA as byte, MCLR as byte)

declare function pic_lvp_upload_firmware(byref fwname as string) as boolean

17 changes: 7 additions & 10 deletions pic/PIC_LVP.tbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include "global.tbh"

dim icsp_target as PIC_TYPE = 0
dim icsp_sda as pl_io_num = PL_IO_NULL
dim icsp_scl as pl_io_num = PL_IO_NULL
dim icsp_mclr as pl_io_num = PL_IO_NULL
Expand Down Expand Up @@ -48,12 +49,6 @@ type firmware
end type


' Global flag to enable/disable SSI use
#define T_ERAB_MS 5
#define T_PINT_MS 6
#define T_PEXT_MS 3
#define T_INCADDR_MS 1

function swab(w as word) as word
swab = ((w shr 8) and &hFF) or ((w and &hFF) shl 8)
end function
Expand Down Expand Up @@ -1340,7 +1335,7 @@ function check_pic(options as byte) as boolean
#ifdef PIC_LVP_DEBUG_PRINT
sys.debugprint(" Detected old " + model + " revision " + str(rev) + "\r\n")
#endif
if (pic and mask) <> PIC_LVP_TARGET_TYPE then
if (pic and mask) <> icsp_target then
#ifdef PIC_LVP_DEBUG_PRINT
sys.debugprint(" Wrong PIC!!!\r\n")
#endif
Expand All @@ -1363,7 +1358,7 @@ function check_pic(options as byte) as boolean
#ifdef PIC_LVP_DEBUG_PRINT
sys.debugprint(" Detected new " + model + "\r\n")
#endif
if pic <> PIC_LVP_TARGET_TYPE then
if pic <> icsp_target then
#ifdef PIC_LVP_DEBUG_PRINT
sys.debugprint(" Wrong PIC!!!\r\n")
#endif
Expand Down Expand Up @@ -1409,7 +1404,7 @@ function program_firmware(byref fw as firmware) as boolean

program_firmware = false

if pic_id(PIC_LVP_TARGET_TYPE, name, rev, options, mask) <> true then
if pic_id(icsp_target, name, rev, options, mask) <> true then
#ifdef PIC_LVP_DEBUG_PRINT
sys.debugprint("Unknown TARGET PIC\r\n")
#endif
Expand Down Expand Up @@ -1533,8 +1528,10 @@ function pic_lvp_upload_firmware(byref fwname as string) as boolean

end function

sub pic_lvp_start(SCL as byte, SDA as byte, MCLR as byte)
sub pic_lvp_start(target as PIC_TYPE, SCL as byte, SDA as byte, MCLR as byte)

icsp_target = target

icsp_scl = SCL
icsp_sda = SDA
icsp_mclr = MCLR
Expand Down
83 changes: 83 additions & 0 deletions tibbits/tbt61/tbt61.tbh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

' VOLTAGE AND CURRENT INPUT SELECTION MAPPING
#define VIN1_DIFFERENTIAL 0
#define VIN2_DIFFERENTIAL 2
#define VIN1+_SINGLE_ENDED 0
#define VIN1-_SINGLE_ENDED 1
#define VIN2+_SINGLE_ENDED 2
#define VIN2-_SINGLE_ENDED 3
#define IIN1_SINGLE_ENDED 4
#define IIN2_SINGLE_ENDED 5

enum TBT61_INIT_RESULT
TBT61_INIT_OK,
TBT61_INIT_ERROR_SPI_NO_EMPTY_CHANNEL,
TBT61_INT_ERROR_NO_TIBBIT_PRESENT,
TBT61_INIT_ERROR_NO_VALID_VERSION,
TBT61_INIT_ERROR_FAULT_CHECK_POWER
end enum

enum TBT61_VOLAGE_TYPE_INPUT
TBT61_VOLTAGE_TWO_DIFFERENTIAL,
TBT61_VOLTAGE_FOUR_SINGLE
end enum

type FW_Info
TibbitType as string(4)
SerialNumber(4) as byte
TestVersion(2) as byte
TestDate(3) as byte
end type

declare function tbt61_init(signature as string, input_type as TBT61_VOLAGE_TYPE_INPUT, cs as pl_io_num, clk as pl_io_num, mosi as pl_io_num, miso as pl_io_num, scl as pl_io_num, sda as pl_io_num, byref tbt_channel as byte) as TBT61_INIT_RESULT
'<b>FUNCTION</b><br><br>
'The function initializes Tibbit #61.<br><br>
'<b>Inputs:</b><br>
'&emsp;<font color="maroon"><b>signature</b></font> - Text identifier of the resource owner.<br>
'&emsp;<font color="maroon"><b>input_type</b></font> - The type of inputs used. The value is a member of the enum type <font color="teal"><b>TBT61_VOLTAGE_TYPE_INPUT</b></font>.<br>
'&emsp;&emsp;<font color="olive"><b>0-TBT61_VOLTAGE_TWO_DIFFERENTIAL</b></font> - two differential volt inputs.<br>
'&emsp;&emsp;<font color="olive"><b>1-TBT61_VOLTAGE_FOUR_SINGLE</b></font> - four volt inputs.<br>
'&emsp;<font color="maroon"><b>cs, clk, mosi, miso,scl, sda</b></font> - are the pin numbers for the corresponding Tibbit control signals according to the Tibbit installation location on the TPS board.<br>
'<br>
'<b>Outputs:</b><br>
'&emsp;The function returns a value of the enum type <font color="teal"><b>TBT61_INIT_RESULT</b></font>.<br>
'&emsp;&emsp;<font color="olive"><b>0-TBT61_INIT_OK</b></font> - Initialization completed successfully.<br>
'&emsp;&emsp;<font color="olive"><b>1-TBT61_INIT_ERROR_SPI_NO_EMPTY_CHANNEL</b></font> - There are no SPI channels available for use..<br>
'&emsp;&emsp;<font color="olive"><b>2-TBT61_INT_ERROR_NO_TIBBIT_PRESENT</b></font> - No Tibbits#61 were found using the pin numbers provided.<br>
'&emsp;&emsp;<font color="olive"><b>3-TBT61_INIT_ERROR_NO_VALID_VERSION</b></font> - Incorrect version of Tibbit's equipment.<br>
'&emsp;&emsp;<font color="olive"><b>4-TBT61_INIT_ERROR_FAULT_CHECK_POWER</b></font> - Tibbit#61 internal power supply testing error.<br>
'&emsp;<font color="maroon"><b>tbt_channel</b></font> - If the function returned result <font color="olive"><b>0-TBT61_INIT_OK</b></font> then this parameter contains the identifier of the current Tibbit.
'All calls to this Tibbit must be made with the passing of this identifier.

declare sub tbt61_release(tbt_channel as byte)
'<b>SUBROUTINE</b><br><br>
'The subroutine releases all allocated resources for this Tibbit#61 instance.<br><br>
'<b>Inputs:</b><br>
'&emsp;<font color="maroon"><b>tbt_channel</b></font> - Tibbit#61 instance identifier.

declare sub tbt61_mode(tbt_channel as byte, input_type as TBT61_VOLAGE_TYPE_INPUT)
'<b>SUBROUTINE</b><br><br>
'This subroutine changes the type of inputs used.<br><br>
'<b>Inputs:</b><br>
'&emsp;<font color="maroon"><b>tbt_channel</b></font> - Tibbit#61 instance identifier.<br>
'&emsp;<font color="maroon"><b>input_type</b></font> - The type of inputs used. The value is a member of the enum type <font color="teal"><b>TBT61_VOLTAGE_TYPE_INPUT</b></font>.<br>
'&emsp;&emsp;<font color="olive"><b>0-TBT61_VOLTAGE_TWO_DIFFERENTIAL</b></font> - two differential volt inputs.<br>
'&emsp;&emsp;<font color="olive"><b>1-TBT61_VOLTAGE_FOUR_SINGLE</b></font> - four volt inputs.

declare function tbt61_read_adc(tbt_channel as byte, channel as byte, byref flags as byte) as real
'<b>FUNCTION</b><br><br>
'The function reads the ADC value for the specified channel number. Error flags are also returned.<br><br>
'<b>Inputs:</b><br>
'&emsp;<font color="maroon"><b>tbt_channel</b></font> - Tibbit#61 instance identifier.<br>
'&emsp;<font color="maroon"><b>channel</b></font> - ADC channel number.<br>
'<b>Outputs:</b><br>
'&emsp;This function returns the measurement result for the specified channel. The result is in <font color="teal"><b>REAL</b></font> format.<br>
'&emsp;<font color="maroon"><b>flags</b></font> - Measurement result flags.

declare function tbt61_read_fw_info(tbt_channel as byte) as FW_Info
'<b>FUNCTION</b><br><br>
'This function returns the <font color="teal"><b>FW_Info</b></font> structure read from the EEPROM of the specified Tibbit#61.<br><br>
'<b>Inputs:</b><br>
'&emsp;<font color="maroon"><b>tbt_channel</b></font> - Tibbit#61 instance identifier.<br>
'<b>Outputs:</b><br>
'&emsp;<font color="maroon"><b>info</b></font> - Read <font color="teal"><b>FW_Info</b></font> structure from Tibbit#61.
Loading

0 comments on commit 6033aa7

Please sign in to comment.