1*61c4878aSAndroid Build Coastguard Worker# Copyright 2024 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker"""Bazel macros for flashing an rp2040 binary.""" 15*61c4878aSAndroid Build Coastguard Worker 16*61c4878aSAndroid Build Coastguard Workerload("@bazel_skylib//rules:native_binary.bzl", "native_binary") 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard Workerdef _flash_rp2( 19*61c4878aSAndroid Build Coastguard Worker name, 20*61c4878aSAndroid Build Coastguard Worker chip, 21*61c4878aSAndroid Build Coastguard Worker binary, 22*61c4878aSAndroid Build Coastguard Worker **kwargs): 23*61c4878aSAndroid Build Coastguard Worker data = [binary] 24*61c4878aSAndroid Build Coastguard Worker args = ["--chip", chip, "$(rootpath " + binary + ")"] 25*61c4878aSAndroid Build Coastguard Worker 26*61c4878aSAndroid Build Coastguard Worker native_binary( 27*61c4878aSAndroid Build Coastguard Worker name = name, 28*61c4878aSAndroid Build Coastguard Worker src = str(Label("//targets/rp2040/py:flash")), 29*61c4878aSAndroid Build Coastguard Worker args = args, 30*61c4878aSAndroid Build Coastguard Worker data = data, 31*61c4878aSAndroid Build Coastguard Worker # Note: out is mandatory in older bazel-skylib versions. 32*61c4878aSAndroid Build Coastguard Worker out = name + ".exe", 33*61c4878aSAndroid Build Coastguard Worker **kwargs 34*61c4878aSAndroid Build Coastguard Worker ) 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard Workerdef flash_rp2040( 37*61c4878aSAndroid Build Coastguard Worker name, 38*61c4878aSAndroid Build Coastguard Worker rp2040_binary, 39*61c4878aSAndroid Build Coastguard Worker **kwargs): 40*61c4878aSAndroid Build Coastguard Worker """Flash the binary to a connected rp2040 device. 41*61c4878aSAndroid Build Coastguard Worker 42*61c4878aSAndroid Build Coastguard Worker Args: 43*61c4878aSAndroid Build Coastguard Worker name: The name of this flash_rp2040 rule. 44*61c4878aSAndroid Build Coastguard Worker rp2040_binary: The binary target to flash. 45*61c4878aSAndroid Build Coastguard Worker **kwargs: Forwarded to the underlying native_binary rule. 46*61c4878aSAndroid Build Coastguard Worker """ 47*61c4878aSAndroid Build Coastguard Worker _flash_rp2(name, "RP2040", rp2040_binary, **kwargs) 48*61c4878aSAndroid Build Coastguard Worker 49*61c4878aSAndroid Build Coastguard Workerdef flash_rp2350( 50*61c4878aSAndroid Build Coastguard Worker name, 51*61c4878aSAndroid Build Coastguard Worker rp2350_binary, 52*61c4878aSAndroid Build Coastguard Worker **kwargs): 53*61c4878aSAndroid Build Coastguard Worker """Flash the binary to a connected rp2350 device. 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker Args: 56*61c4878aSAndroid Build Coastguard Worker name: The name of this flash_rp2350 rule. 57*61c4878aSAndroid Build Coastguard Worker rp2350_binary: The binary target to flash. 58*61c4878aSAndroid Build Coastguard Worker **kwargs: Forwarded to the underlying native_binary rule. 59*61c4878aSAndroid Build Coastguard Worker """ 60*61c4878aSAndroid Build Coastguard Worker _flash_rp2(name, "RP2350", rp2350_binary, **kwargs) 61