]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
din: Simplify din_spi_get_command_from_enum() + other cleanups
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 20 Sep 2013 13:47:14 +0000 (15:47 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 20 Sep 2013 14:01:52 +0000 (16:01 +0200)
rpp/include/drv/din.h
rpp/src/drv/din.c

index 2e30e3c2f0f40b759725a01240658b40a9d8ac0c..918feba3bf0c34b39ddc700cc4055f4b01b78c50 100644 (file)
@@ -58,7 +58,7 @@ enum SpiCmdTable
  * @param[in] and_ and_ value is bitwise AND by shadow register for the command
  * @param[in] xor_ xor_ value is bitwise XOR by product of shadow register AND
  *                                     and_
- * @return return spi response
+ * @return return spi response or zero in case of error
  */
 uint16_t din_set_reg(enum SpiCmdTable cmd_index, uint16_t and_, uint16_t xor_);
 
index e35fae1d137f51b64a7c289ddbff8d8909c904c8..baa8c14f28d8aef18a402c0365fce530ebb018b9 100644 (file)
@@ -59,15 +59,6 @@ const static uint32_t dsc_pin_map[8U] = {
  */
 int din_spi_transfer_mst(const uint32_t din_spi_cmd);
 
-/**
- * This find an index in register list
- * @param index
- * @return command
- */
-uint32_t din_spi_get_command_from_enum(const uint8_t index);
-
-
-
 /******************************************************************************
 *   Close variable declaration sections
 ******************************************************************************/
@@ -79,6 +70,18 @@ uint32_t din_spi_get_command_from_enum(const uint8_t index);
 #define DACA_INIT_VAL   (_BV(13) | _BV(12)          )
 #define DACB_INIT_VAL   (_BV(13) | _BV(12) | _BV(15))
 
+/**
+ * This find an index in register list
+ * @param command
+ * @return index
+ */
+static uint32_t enum2cmd(const enum SpiCmdTable index)
+{
+       if (index == DIN_RESET_CMD)
+               return 0x007F0000;
+       else
+               return index << 16;
+}
 
 /* Public functions */
 /* ---------------- */
@@ -86,16 +89,14 @@ uint32_t din_spi_get_command_from_enum(const uint8_t index);
 uint16_t din_set_reg(
                enum SpiCmdTable spi_cmd_index, uint16_t clear_mask, uint16_t xor_mask)
 {
-       if ((uint8_t)spi_cmd_index > DIN_NUM_SPI_CMD){
+       if (spi_cmd_index >= DIN_NUM_SPI_CMD) {
                return 0;
        }
-       else{}
 
        shadow_reg_list[spi_cmd_index] =
                        shadow_reg_list[spi_cmd_index] & ~clear_mask ^ xor_mask;
 
-       uint32_t din_spi_cmd = din_spi_get_command_from_enum(spi_cmd_index) |
-                       shadow_reg_list[spi_cmd_index];
+       uint32_t din_spi_cmd = enum2cmd(spi_cmd_index) | shadow_reg_list[spi_cmd_index];
 
        return din_spi_transfer_mst(din_spi_cmd);
 }
@@ -185,20 +186,3 @@ int din_spi_transfer_mst(const uint32_t din_spi_cmd) {
                commands);
     return din_spi_resp;
 }
-/**
- * This find an index in register list
- * @param command
- * @return index
- */
-uint32_t din_spi_get_command_from_enum(const uint8_t index)
-{
-       uint32_t command = 0x0;
-
-       if (index == DIN_RESET_CMD){
-               return 0x007F0000;
-       }
-       else {}
-
-       command = index << 16;
-       return command;
-}