尹小舟 发表于 2024-5-1 16:37

FireBeetle 2 ESP32 C6开发板 __ Arduino接口声明讲解与GPIO输入DEMO_CDC串口使用

本帖最后由 尹小舟 于 2024-5-1 16:48 编辑

<p><span style="font-size:18px;"><strong>1.Arduino接口声明讲解</strong></span></p>

<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;tKdn-1714215366374&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;hg8R-1714215366373&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;Arduino接口声明讲解&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;color&quot;,&quot;value&quot;:&quot;#4d4d4d&quot;},{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgb(255, 255, 255)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:16},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;SimHei&quot;}]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Jfnq-1714213012315&quot;,&quot;name&quot;:&quot;code&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;language&quot;:&quot;&quot;,&quot;theme&quot;:&quot;default&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;wyUy-1714213012304&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;PtNn-1714213012303&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias(\&quot;__pinMode\&quot;)));&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;eIem-1714213012306&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;8ayb-1714213012305&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias(\&quot;__digitalWrite\&quot;)));&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Fcqa-1714213012308&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WxzP-1714213012307&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias(\&quot;__digitalRead\&quot;)));&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;A2Xv-1714213012310&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;t4C9-1714213012309&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias(\&quot;__attachInterrupt\&quot;)));&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;tz7V-1714213012312&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;QBoG-1714213012311&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__ ((weak, alias(\&quot;__attachInterruptArg\&quot;)));&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;RK92-1714213012314&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;IKZj-1714213012313&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias(\&quot;__detachInterrupt\&quot;)));&quot;,&quot;marks&quot;:[]}]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;G3D2-1714213012336&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3ZOC-1714213012333&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;color&quot;,&quot;value&quot;:&quot;#4d4d4d&quot;},{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgb(255, 255, 255)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:16},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;SimHei&quot;}]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;6dpq-1714215979910&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;ZU5Q-1714215979909&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;这行代码是C语言中的一个声明,主要用在嵌入式编程中,特别是与Arduino兼容的硬件上。我将逐一解释这行代码的各个部分。&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;V50M-1714215981373&quot;,&quot;name&quot;:&quot;list-item&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;listId&quot;:&quot;euKb-1714215981390&quot;,&quot;listLevel&quot;:1,&quot;listType&quot;:&quot;ordered&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;w2hJ-1714215981372&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;extern&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{&quot;index&quot;:1}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;chuA-1714215981375&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GPz5-1714215981374&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;: 这是一个关键字,用于声明一个变量或函数,但不在当前源文件中定义它。这通常意味着该函数或变量的定义在另一个源文件中,或者在链接时提供的库中。&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;bwf2-1714215981377&quot;,&quot;name&quot;:&quot;list-item&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;listId&quot;:&quot;euKb-1714215981390&quot;,&quot;listLevel&quot;:1,&quot;listType&quot;:&quot;ordered&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;vsch-1714215981376&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;void pinMode(uint8_t pin, uint8_t mode)等函数&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{&quot;index&quot;:2}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;QfgL-1714215981379&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;hbDl-1714215981378&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;Arduino接口函数&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;nqNh-1714215981381&quot;,&quot;name&quot;:&quot;list-item&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;listId&quot;:&quot;euKb-1714215981390&quot;,&quot;listLevel&quot;:1,&quot;listType&quot;:&quot;ordered&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;LYD3-1714215981380&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;__attribute__ ((weak, alias(\&quot;__pinMode\&quot;)));&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{&quot;index&quot;:3}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Chy4-1714215981383&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;lByF-1714215981382&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot; ((weak, alias(\&quot;__pinMode\&quot;)))&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;bold&quot;},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Arial&quot;}]},{&quot;text&quot;:&quot;: 这是GCC编译器的一个特性,它用于为函数或变量添加特殊的属性。&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ROY8-1714215981385&quot;,&quot;name&quot;:&quot;list-item&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;listId&quot;:&quot;GU73-1714215981391&quot;,&quot;listLevel&quot;:2,&quot;listType&quot;:&quot;unordered&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;KVY3-1714215981384&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;weak: 这个属性表示这个函数是一个弱定义。如果有其他同名的非弱定义函数存在,那么在链接时,这个弱定义函数会被忽略。这在提供默认实现的同时允许用户或库提供自定义实现时非常有用。&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{&quot;index&quot;:1}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;PinE-1714215981387&quot;,&quot;name&quot;:&quot;list-item&quot;,&quot;data&quot;:{&quot;version&quot;:1,&quot;listId&quot;:&quot;GU73-1714215981391&quot;,&quot;listLevel&quot;:2,&quot;listType&quot;:&quot;unordered&quot;},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;qTZs-1714215981386&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;alias(\&quot;__pinMode\&quot;): 这个属性表示&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;函数是另一个函数&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;__pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;的别名。这意味着在代码中调用&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;实际上会调用&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;__pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;。这通常用于允许用户通过更友好的名称(在这种情况下是&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;)来访问底层或内部的函数(&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;__pinMode&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgba(27, 31, 35, 0.05)&quot;},{&quot;type&quot;:&quot;fontSize&quot;,&quot;value&quot;:12},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Courier New&quot;}]},{&quot;text&quot;:&quot;)。&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{&quot;index&quot;:2}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;3PzJ-1714215981389&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;u7eE-1714215981388&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;综上所述,这些代码声明了适配的Arduino接口,这个适配的接口是弱的,&quot;,&quot;marks&quot;:[]},{&quot;text&quot;:&quot;允许用户或特定库提供自定义实现。&quot;,&quot;marks&quot;:[{&quot;type&quot;:&quot;color&quot;,&quot;value&quot;:&quot;#05073b&quot;},{&quot;type&quot;:&quot;backgroundColor&quot;,&quot;value&quot;:&quot;rgb(253, 253, 254)&quot;},{&quot;type&quot;:&quot;fontFamily&quot;,&quot;value&quot;:&quot;Arial&quot;}]}]}],&quot;state&quot;:{}}]">
<p>右键选择Go to Definition 可以跳到以下代码</p>

<pre>
<code>extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode")));
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead")));
extern void attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) __attribute__ ((weak, alias("__attachInterrupt")));
extern void attachInterruptArg(uint8_t pin, voidFuncPtrArg handler, void * arg, int mode) __attribute__ ((weak, alias("__attachInterruptArg")));
extern void detachInterrupt(uint8_t pin) __attribute__ ((weak, alias("__detachInterrupt")));</code></pre>

<p>这行代码是C语言中的一个声明,主要用在嵌入式编程中,特别是与Arduino兼容的硬件上。我将逐一解释这行代码的各个部分。</p>

<ol yne-block-type="list">
        <li>extern</li>
</ol>

<p>: 这是一个关键字,用于声明一个变量或函数,但不在当前源文件中定义它。这通常意味着该函数或变量的定义在另一个源文件中,或者在链接时提供的库中。</p>

<ol start="2" yne-block-type="list">
        <li>void pinMode(uint8_t pin, uint8_t mode)等函数</li>
</ol>

<p>Arduino接口函数</p>

<ol start="3" yne-block-type="list">
        <li>__attribute__ ((weak, alias(&quot;__pinMode&quot;)));</li>
</ol>

<p>&nbsp;((weak, alias(&quot;__pinMode&quot;))): 这是GCC编译器的一个特性,它用于为函数或变量添加特殊的属性。</p>

<p>综上所述,这些代码声明了适配的Arduino接口,这个适配的接口是弱的,允许用户或特定库提供自定义实现。</p>
</article>

<p>&nbsp;</p>

<p><strong>2.GPIO输入DEMO</strong></p>

<p>按下SW1 亮蓝灯,按下SW2亮红灯</p>

<p>d0865db13fb35299419ec7b4e8c3672e<br />
&nbsp;</p>

<pre>
<code>
#define LED_BLUE    SCK
#define LED_RED   MOSI
#define SW1_PIN_INPUT 17
#define SW2_PIN_INPUT 16
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_RED, OUTPUT);
pinMode(SW1_PIN_INPUT, INPUT_PULLUP);    /* 设置key引脚为上拉输入模式 */
pinMode(SW2_PIN_INPUT, INPUT_PULLUP);    /* 设置key引脚为上拉输入模式 */

}

// the loop function runs over and over again forever
void loop() {
if(digitalRead(SW1_PIN_INPUT) == 0)
{
      delay(20);                      // wait for a second
      if(digitalRead(SW1_PIN_INPUT) == 0)
      {
         digitalWrite(LED_BLUE, HIGH);// turn the LED on (HIGH is the voltage level)
         digitalWrite(LED_RED, LOW);   // turn the LED off by making the voltage LOW
      }
      
}
if(digitalRead(SW2_PIN_INPUT) == 0)
{
      delay(20);                      // wait for a second
      if(digitalRead(SW2_PIN_INPUT) == 0)
      {
          digitalWrite(LED_BLUE, LOW);// turn the LED on (HIGH is the voltage level)
          digitalWrite(LED_RED, HIGH);   // turn the LED off by making the voltage LOW
      }
}
}</code></pre>

<p>&nbsp;</p>

<p>3.关于上篇串口的问题</p>

<p> &nbsp;</p>

<p>&nbsp;</p>

<p></p>

<p>将USB CDC On BOOT选择&quot;Enabled&quot;&nbsp;</p>

Jacktang 发表于 2024-5-4 07:37

<p>些代码声明了适配的Arduino接口,这个适配的接口是弱的,弱到什么地步,怎么讲</p>
页: [1]
查看完整版本: FireBeetle 2 ESP32 C6开发板 __ Arduino接口声明讲解与GPIO输入DEMO_CDC串口使用