> I'll try to let the max7219 libraries use either the master_spi_hw or the master_spi_sw library.
It sounds like you are trying to put the SPI definitions/include in your library, but I think it should go in your sample files. Think of SPI like Serial, where we define speed, pins, etc in our sample. The code I gave you is to put in your sample, and can be easily switched out between software/hardware by the user. > But then I found some inconveniences: these libs use different names for > the same functionality: e.g. spi_master_hw_exchange and > spi_master_sw_exchange. Why not let both use spi_master_exchange > (without hw or sw qualifier)? I think me and Seb had decided on the current implementation. Again, look at serial, which has similar inconsistencies. These are fixed with alias. alias spi_master is spi_master_sw or alias spi_master is spi_master_hw The alias will be in the sample. Your libs would use spi_master As for the init procedure, they could be renamed, what do you suggest? spi_sw_init() and spi_hw_init()? Using different procedure names gives the possibility of using both libs at the same time. For example, if two chips use different SPI modes and speed is a concern. Of course the mode can be changed in the middle of a sample, hence the constant in SD_CARD lib and others. There are if defined statements in libs for this. You might want to look at sd_card lib/sample. Init is called in the samples. alias sd_force_spi_mode is spi_master_hw_set_mode_11 -- always set spi mode to 1,1 > Thanks for the suggestion! I could choose the right SPI library at > compile time depending on a user defined constant or/and the presence of > MSSP registers. Again, putting the code I provided in the sample will fix this issue. > Table 1 in SPI introduction contains errors (such as bytes->bits, > which was already reported It's part of the planned website upgrades. I haven't decided weather we should continue using DITA for the tutorial book. DITA makes a nice book, but makes it more difficult for people to contribute to it. Please let me know about other errors you find, I'll write them down, or you can open an issue. > I'm not working on any SPI library let alone creating a new one. But > I'll try to reduce redundancy with the MAX7219 libraries by using an SPI > library (when possible and appropriate). sorry, I did mean it's nice to see MAX7219 using SPI :) > This is not exactly the code example I'm looking for since is declares > aliases for pins_sdi/sdo/sck, which means it uses software-SPI on the > same pins as hardware-SPI would use. Thus (1) this is only valid for > PICs with MSSP and (2) why would you use software-SPI in this case? Maybe this will be seen differently for you if you do put it in the sample, I'll give you more examples here. Of course the pin defs are controlled by the user, and thus the user would change them from pin_sdi to pin_a0 or whatever they need. > 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 The user may only need to use one of these on a different pin since something else is in the way. In your case, you might change them all. > PICs with MSSP You had previously added aliases for SPI in device files, maybe some are missing or can't be aliased at all since there is no SPI module. ok... on with the examples (which would go in sample files). This is how I handle both SPI and Serial. SPI hw/sw can be changed easily by the user. Serial hw/sw can be changed easily easily by the user. The aliases would be called in the lib, such as spi_master or serial_data. I'm providing both SPI and serial hw/sw just to show the usefulness of aliases. ----------------------------------- -- 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 ----------------------------------- -- 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 ----------------------------------- -- 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 ----------------------------------- -- 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 ----------------------------------- 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.
