Here's the serial block I use in all my samples.
The aliases are not required, but I find them useful so I can easily change
to serial software if I want just by changing the serial code block, and
not the rest of my code. This way both serial hardware and serial software
have "serial_data" instead of "serial_hw_data" or "serial_sw_data".
-- setup uart for communication
const serial_hw_baudrate = 115200 -- set the baudrate
include serial_hardware
serial_hw_init()
-- some aliases so it is easy to change from serial hw to serial sw.
alias serial_write is serial_hw_write
alias serial_read is serial_hw_read
alias serial_data is serial_hw_data
alias serial_data_available is serial_hw_data_available
OR
-- setup serial software
const serial_sw_baudrate = 115200
alias serial_sw_tx_pin is pin_tx
alias serial_sw_rx_pin is pin_tx
pin_tx_direction = output
pin_rx_direction = input
include serial_software
serial_sw_init()
-- some aliases so it is easy to change from serial hw to serial sw.
alias serial_write is serial_sw_write
alias serial_read is serial_sw_read
alias serial_data is serial_sw_data
Alias is also good for SPI (you'll need to change it for spi_master_hw2).
Your lib can then use "spi_master" instead of "spi_master_hw". This way you
can switch to the spi software lib easy if needed.
-- setup SPI library
include spi_master_hw -- includes the spi library
-- define spi inputs/outputs
pin_sdi_direction = input -- spi input
pin_sdo_direction = output -- spi output
pin_sck_direction = output -- spi clock
--
spi_init(SPI_MODE_11,SPI_RATE_FOSC_4) -- init spi, choose mode and speed
alias spi_master is spi_master_hw
alias spi_master_exchange is spi_master_hw_exchange
OR
-- setup SPI software
alias spi_master_sw_sdi is pin_sdi
alias spi_master_sw_sdi_direction is pin_sdi_direction
alias spi_master_sw_sdo is pin_sdo
alias spi_master_sw_sdo_direction is pin_sdo_direction
alias spi_master_sw_sck is pin_sck
alias spi_master_sw_sck_direction is pin_sck_direction
-- define spi inputs/outputs
spi_master_sw_sdi_direction = input -- spi input
spi_master_sw_sdo_direction = output -- spi output
spi_master_sw_sck_direction = output -- spi clock
--
include spi_master_sw
spi_master_sw_init(SPI_MODE_11,0) -- init spi, choose mode
alias spi_master is spi_master_sw
alias spi_master_set_speed is spi_master_sw_set_speed
alias spi_master_set_mode is spi_master_sw_set_mode
By the way, I like the fact that you used this code in your lib so you can
use multiple devices with different spi modes:
if defined(sst25vf_force_spi_mode) == true then
sst25vf_force_spi_mode()
end if
Your code is good as is, these are only suggestions.
Matt.
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/jallib.
For more options, visit https://groups.google.com/d/optout.