3 Replies Latest reply on Jun 21, 2018 7:15 AM by BoTa_264741

    Write code independent of component name


      Hi all,


      I'm still new to PSoC (and PSoC Creator) world: I would like to port some libraries that I wrote for STM32 MCU to PSoC, but I have some doubts about it.


      The libraries that I wrote are intended to be used with MEMS sensors (temperature, pressure, and humidity) which communicate with the MCU over I2C. When I wrote them for STM32 MCU, I wanted them to be independent of the I2C interface chosen (I2C1, I2C2, I2C3,..), so that the programmer could choose which I2C to be used. Therefore, my code looked like this:

      // Function prototype - I2C_TypeDef pointer
      void readTemperature(I2C_TypeDef *I2C, SensorStruct sensor);
      int main(void)
           SensorStruct mySensor;
                // Do some stuff

      In PSoC, can I do something similar? My problem right now is that, if I write a library, I'll need to use some I2C methods, but these methods have to be called with the name of the component. So if I change the name of the component, I need to change it everywhere in my code, as follows:

      // Programmer used I2C component naming it I2C
      I2C_MasterSendStart(SLAVE_ADDRESS, READ);
      // Programmer used I2C component naming it I2C_1
      I2C_1_MasterSendStart(SLAVE_ADDRESS, READ);

      What kind of approach do you suggest me?


      Thank you in advance,