<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Feature Request: API should use peripheral instance index instead of peripheral base address in MCUXpresso SDK</title>
    <link>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1557388#M4013</link>
    <description>&lt;P&gt;Using Base address as first parameter is also &lt;SPAN&gt;common practice&lt;/SPAN&gt; of API, you can see the competitor's SDK (eg, STM&amp;nbsp;StdPeriph_Driver )&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2022 01:14:08 GMT</pubDate>
    <dc:creator>jay_heng</dc:creator>
    <dc:date>2022-11-22T01:14:08Z</dc:date>
    <item>
      <title>Feature Request: API should use peripheral instance index instead of peripheral base address</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1555076#M3997</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Every time I use a&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;standard SDK driver&lt;/EM&gt; I wonder why I have to put in the register base address of the peripheral instance which the driver is using.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In my opinion it would be much more convenient if one just had to enter the index of the peripheral instance (or 0 if the peripheral has only one instance).&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example when using PWM (see "fsl_ctimer.h"), I have to call &lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;CTIMER_SetupPwm()&lt;/FONT&gt;&lt;/STRONG&gt; function to setup PWM:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;status_t CTIMER_SetupPwm(CTIMER_Type *base,
                         const ctimer_match_t pwmPeriodChannel,
                         ctimer_match_t matchChannel,
                         uint8_t dutyCyclePercent,
                         uint32_t pwmFreq_Hz,
                         uint32_t srcClock_Hz,
                         bool enableInt)
{
    assert(pwmFreq_Hz &amp;gt; 0U);

    uint32_t reg;
    uint32_t period, pulsePeriod = 0;
    uint32_t timerClock = srcClock_Hz / (base-&amp;gt;PR + 1U);
    uint32_t index      = CTIMER_GetInstance(base);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;From the signature you can tell that I have to provide the base address of the timer instance, i.e.,&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;CTIMER0&lt;/FONT&gt;&lt;/STRONG&gt;, &lt;FONT face="andale mono,times"&gt;&lt;STRONG&gt;CTIMER1&lt;/STRONG&gt;&lt;/FONT&gt;, etc. (see the register definition file of the specific MCU).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;CTIMER_SetupPwm()&lt;/FONT&gt;&lt;/STRONG&gt; &amp;nbsp;then calls&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="andale mono,times"&gt;CTIMER_GetInstance(base)&lt;/FONT&gt;&lt;/STRONG&gt; to identify the numerical index of the timer instance. To do this is loops through all base addresses&amp;nbsp;&lt;FONT face="andale mono,times"&gt;&lt;STRONG&gt;s_ctimerBases[]&lt;/STRONG&gt;&lt;/FONT&gt; of available timer instances and checks whether it matches with the provided base address.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This seems cumbersome and superfluous.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Suggestion:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;API functions should take the index of the peripheral instance as first parameter (instead of register base address).&lt;/P&gt;&lt;P&gt;This would get rid of the for-loop and would improve usability of the driver as one would not have to look up the name of the base address but could just enter the index of the peripheral instance.&lt;/P&gt;&lt;P&gt;In the example:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;status_t CTIMER_SetupPwm(uint32_t index,
                         const ctimer_match_t pwmPeriodChannel,
                         ctimer_match_t matchChannel,
                         uint8_t dutyCyclePercent,
                         uint32_t pwmFreq_Hz,
                         uint32_t srcClock_Hz,
                         bool enableInt) {

CTIMER_Type *base = s_ctimerBases[index];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That would do it.&lt;/P&gt;&lt;P&gt;Does that make sense?&lt;/P&gt;&lt;P&gt;Cheers&lt;BR /&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 16:56:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1555076#M3997</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2022-11-16T16:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Request: API should use peripheral instance index instead of peripheral base address</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1555331#M4000</link>
      <description>&lt;P&gt;As far as i know, t&lt;SPAN&gt;here are historical reasons for this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;on some devices, peripheral instance starts from 0, but on other devices, peripheral instance starts from 1, this is due to device header file differences. as driver is common for all devices, that's why you see all the APIs take base address instead of instance here.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 00:42:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1555331#M4000</guid>
      <dc:creator>jay_heng</dc:creator>
      <dc:date>2022-11-17T00:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Request: API should use peripheral instance index instead of peripheral base address</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1557251#M4009</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/40101"&gt;@jay_heng&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your reply. If those inconsistencies are a historical residue, why not start to clean up the API in order to improve consistency?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just don't see a reason why some API calls require the index of a peripheral instance, e.g.,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/* Get FLEXCOMM input clock */
/*! brief Return Frequency of flexcomm input clock
* param id : flexcomm instance id
* return Frequency value
*/
uint32_t CLOCK_GetFlexCommInputClock(uint32_t id);&lt;/LI-CODE&gt;&lt;P&gt;while other require the base address of the peripheral instance, e.g.,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;/*! @brief Initializes FLEXCOMM and selects peripheral mode according to the second parameter. */
status_t FLEXCOMM_Init(void *base, FLEXCOMM_PERIPH_T periph);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a start, you could always add a second function with same functionality but different signature that uses the index instead of base address as first parameter.&lt;/P&gt;&lt;P&gt;Just saying...&lt;BR /&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 15:29:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1557251#M4009</guid>
      <dc:creator>danielholala</dc:creator>
      <dc:date>2022-11-21T15:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Request: API should use peripheral instance index instead of peripheral base address</title>
      <link>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1557388#M4013</link>
      <description>&lt;P&gt;Using Base address as first parameter is also &lt;SPAN&gt;common practice&lt;/SPAN&gt; of API, you can see the competitor's SDK (eg, STM&amp;nbsp;StdPeriph_Driver )&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 01:14:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-SDK/Feature-Request-API-should-use-peripheral-instance-index-instead/m-p/1557388#M4013</guid>
      <dc:creator>jay_heng</dc:creator>
      <dc:date>2022-11-22T01:14:08Z</dc:date>
    </item>
  </channel>
</rss>

