]> granicus.if.org Git - esp-idf/commitdiff
fix(spi_master): fix the command field to make it more intuitive to use.
authormichael <xiaoxufeng@espressif.com>
Thu, 17 Aug 2017 11:41:53 +0000 (19:41 +0800)
committermichael <xiaoxufeng@espressif.com>
Mon, 21 Aug 2017 12:37:57 +0000 (20:37 +0800)
components/driver/include/driver/spi_master.h
components/driver/spi_master.c
components/driver/test/test_spi_master.c
components/soc/esp32/include/soc/spi_struct.h

index 04f4c069944d26f6987a4dd0be8cab55b8acb167..09456c6e59a4f56ce8eea090bf907b47e0529908 100644 (file)
@@ -71,10 +71,12 @@ typedef struct {
  */
 struct spi_transaction_t {
     uint32_t flags;                 ///< Bitwise OR of SPI_TRANS_* flags
-    uint16_t command;               ///< Command data, of which the length is set in the command_bits of spi_device_interface_config_t.
-    uint64_t addr;                  ///< Address data, of which the length is set in the address_bits of spi_device_interface_config_t.
-                                    ///< <b>NOTE: this field is re-written to be used in a new way.</b> 
-                                    ///< - Example: write 0x123400 and address_bits=24 to send address of 0x12, 0x34, 0x00.  
+    uint16_t cmd;                   ///< Command data, of which the length is set in the ``command_bits`` of spi_device_interface_config_t.
+                                    ///< <b>NOTE: this field, used to be "command" in ESP-IDF 2.1 and before, is re-written to be used in a new way in ESP-IDF 3.0.</b>
+                                    ///< - Example: write 0x0123 and command_bits=12 to send command 0x12, 0x3_ (in previous version, you may have to write 0x3_12).
+    uint64_t addr;                  ///< Address data, of which the length is set in the ``address_bits`` of spi_device_interface_config_t.
+                                    ///< <b>NOTE: this field, used to be "address" in ESP-IDF 2.1 and before, is re-written to be used in a new way in ESP-IDF3.0.</b> 
+                                    ///< - Example: write 0x123400 and address_bits=24 to send address of 0x12, 0x34, 0x00 (in previous version, you may have to write 0x12340000).  
     size_t length;                  ///< Total data length, in bits
     size_t rxlength;                ///< Total data length received, should be not greater than ``length`` in full-duplex mode. (0 defaults this to the value of ``length``)
     void *user;                     ///< User-defined variable. Can be used to store eg transaction ID.
index e6175ebae9579d8418720b2111eaf3ab9c336264..ae906ee8916c3196180913b6e060f14fbfb2e966 100644 (file)
@@ -550,10 +550,9 @@ static void IRAM_ATTR spi_intr(void *arg)
             host->hw->miso_dlen.usr_miso_dbitlen=trans->length-1;
         }
 
-        host->hw->user2.usr_command_value=trans->command;
-               
-        // NOTE: WE CHANGED THE WAY USING ADDRESS FIELD. Now address should be filled in, in the following format:
-        // Example: write 0x123400 and address_bits=24 to send address 0x12, 0x34, 0x00 (in previous version, you may have to write 0x12340000)
+        // output command will be sent from bit 7 to 0 of command_value, and then bit 15 to 8 of the same register field.
+        uint16_t command = trans->cmd << (16-dev->cfg.command_bits);    //shift to MSB
+        host->hw->user2.usr_command_value = (command>>8)|(command<<8);  //swap the first and second byte
         // shift the address to MSB of addr (and maybe slv_wr_status) register. 
         // output address will be sent from MSB to LSB of addr register, then comes the MSB to LSB of slv_wr_status register. 
         if (dev->cfg.address_bits>32) {
index b6029f1f309750d02f4327b5afc09939074660ee..5d35f4eee68a19200605ac4ad13e5bbe892237bc 100644 (file)
@@ -132,7 +132,7 @@ static void spi_test(spi_device_handle_t handle, int num_bytes) {
     t.tx_buffer=sendbuf;
     t.rx_buffer=recvbuf;
     t.addr=0xA00000000000000FL;
-    t.command=0x55;
+    t.cmd=0x55;
 
     printf("Transmitting %d bytes...\n", num_bytes);
     ret=spi_device_transmit(handle, &t);
index 10bdcbb1c1aceb27338fb2467aa2c1ad33fc8bc2..2d2081749046c11c606db1b8dae27b6052f3ef0e 100644 (file)
@@ -143,7 +143,7 @@ typedef volatile struct {
     } user1;
     union {
         struct {
-            uint32_t usr_command_value: 16;                 /*The value of  command.*/
+            uint32_t usr_command_value: 16;                 /*The value of  command. Output sequence: bit 7-0 and then 15-8.*/
             uint32_t reserved16:        12;                 /*reserved*/
             uint32_t usr_command_bitlen: 4;                 /*The length in bits of command phase. The register value shall be (bit_num-1)*/
         };