1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

オブジェクト指向Cコンパイラcomelangがraspi picoで動きました。

Posted at

この方法はMacBookでの方法です。

まずMacBookにPICO SDKをインストールしてください。
インストール方法は検索するかAIに聞いてください。
git cloneしてcmakeでビルド
環境変数PICO_SDK_PATHを設定するだけだったと思います。

comelangを使ったコードを転送する前に
まず普通にプロジェクトを作ってください。

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)

project(led_project)

pico_sdk_init()

add_executable(led led2.c)

# 必要なライブラリをリンク
target_link_libraries(led pico_stdlib hardware_gpio pico_malloc)

# フラッシュ設定
pico_enable_stdio_usb(led 1)
pico_enable_stdio_uart(led 0)

pico_add_extra_outputs(led)

led2.c

#include "pico/stdlib.h"

int main() {
    const uint LED_PIN = 25;  // PicoのオンボードLEDピン
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

    while(true) {
        gpio_put(LED_PIN, 1);  // LED ON
        sleep_ms(500);         // 500ms待機
        gpio_put(LED_PIN, 0);  // LED OFF
        sleep_ms(500);         // 500ms待機
    }

    return 0;
}

pico_sdk_import.cmakeがカレントディレクトリに必要みたいです。
SDKからコピーしてきてください。

> mkdir build && (cd build && cmake .. && make)

ラズパイPICOのbootableボタンを押してパソコンに接続。Mac Book AirならUSB-C <=> USB-A端子が必要です。

> cd build
> cp led.uf2 /Volumes/RPI-RP2

コピーするとLEDの点火が始まります。

いよいよcomelangを使ったコードを動かします。
pico_config_platform_headers.h
pico_config_extra_headers.h
をPICO SDKからコピーしてください。

led.c

#include <comelang-pico.h>

int main() {
//    stdio_usb_init();  // USB出力の初期化
    const uint LED_PIN = 25;  // PicoのオンボードLEDピン
    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);

    var li = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    foreach(it, li) {
        for(int i=0; i<5; i++) {
            gpio_put(LED_PIN, 1);  // LED ON
            sleep_ms(50*it);         // 50ms待機
            gpio_put(LED_PIN, 0);  // LED OFF
            sleep_ms(50*it);         // 50ms待機
        }
    }
    
    while(true) {
        gpio_put(LED_PIN, 0);  // LED OFF
    }

    return 0;
}
comelang -pico led.c

でコンパイルに成功すればled.c.cができます。

> cp led.c.c led2.c

もう一度コンパイルします。

> (rm -rf build && mkdir build && cd build && cmake .. && make)
> cd build
> cp led.uf2 /Volumes/RPI-RP2

今度は点火が最初は早いですが、徐々に遅くなります。

注意点は一度プロジェクトとビルドしておかないとcomelang -pico led.cが成功しない点です
ヘッダーが足りずにコンパイルに失敗すると思います。

モダンなコンパイラをpicoでも楽しんでください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?