Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Consider making more board agnostic code possible #589

Open
DmitryOlshansky-google opened this issue Aug 4, 2016 · 1 comment
Open

Consider making more board agnostic code possible #589

DmitryOlshansky-google opened this issue Aug 4, 2016 · 1 comment

Comments

@DmitryOlshansky-google
Copy link
Contributor

DmitryOlshansky-google commented Aug 4, 2016

We should consider some common capabilities of the boards and have a set of interfaces, like PWM capable boards.

Consider current samples for PWM.

Nucleo board:

import 'dart:dartino';
import 'package:stm32/stm32f411re_nucleo.dart';
import 'package:stm32/gpio.dart';

main() {
  STM32F411RENucleo nucleo = new STM32F411RENucleo();
  STM32Gpio gpio = nucleo.gpio;
  // Initialize all PWM pins
  var pins = [
    gpio.initPwmOutput(STM32F411RENucleo.D3),
    gpio.initPwmOutput(STM32F411RENucleo.D5),
    gpio.initPwmOutput(STM32F411RENucleo.D6),
    gpio.initPwmOutput(STM32F411RENucleo.D9),
    gpio.initPwmOutput(STM32F411RENucleo.D10),
    gpio.initPwmOutput(STM32F411RENucleo.D11)
  ];
  // Set different frequences on each pin.
  // Note: these that share a timer will share the frequency.
  for(int i = 0; i < pins.length; i++){
    pins[i].prescaler = (i + 1) * 100 - 1;
    pins[i].period = 9999;
    pins[i].output(i * 1000 + 1000);
  }
  while(true){
    sleep(1);
  }
}

And Discovery board:

import 'dart:dartino';
import 'package:stm32/stm32f746g_disco.dart';
import 'package:stm32/gpio.dart';

main() {
  STM32F746GDiscovery board = new STM32F746GDiscovery();
  STM32Gpio gpio = board.gpio;
  // Initialize all PWM pins
  var pins = [
    gpio.initPwmOutput(STM32F746GDiscovery.D3),
    gpio.initPwmOutput(STM32F746GDiscovery.D5),
    gpio.initPwmOutput(STM32F746GDiscovery.D6),
    gpio.initPwmOutput(STM32F746GDiscovery.D9),
    gpio.initPwmOutput(STM32F746GDiscovery.D10),
    gpio.initPwmOutput(STM32F746GDiscovery.D11)
  ];
  // Set different frequences on each pin.
  // Note: these that share a timer will share the frequency.
  for(int i = 0; i < pins.length; i++){
    pins[i].prescaler = (i + 1) * 100 - 1;
    pins[i].period = 9999;
    pins[i].output(i * 1000 + 1000);
  }
  while(true){
    sleep(1);
  }
}
@jakobr-google
Copy link
Contributor

Related to #559.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants