intial commit
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into the executable file.
|
||||
|
||||
The source code of each library should be placed in a separate directory
|
||||
("lib/your_library_name/[Code]").
|
||||
|
||||
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
Example contents of `src/main.c` using Foo and Bar:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries by scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "mp32.h"
|
||||
#include "Extra.h"
|
||||
|
||||
#ifdef EXTRA_MOTORS
|
||||
const int _OUT0[4] = { 0x7FFF, 0xBFFF, 0xDFFF, 0xEFFF };
|
||||
const int _OUT1[4] = { 0x8000, 0x4000, 0x2000, 0x1000 };
|
||||
const int _EN[4] = { M1EN, M2EN, M3EN, M4EN };
|
||||
static bool extraMotorsInitialized = false;
|
||||
|
||||
static void initExtraMotors() {
|
||||
initMotor();
|
||||
pinMode(M3DIR, OUTPUT);
|
||||
pinMode(M4DIR, OUTPUT);
|
||||
pinMode(M3EN, OUTPUT);
|
||||
pinMode(M4EN, OUTPUT);
|
||||
digitalWrite(M3EN, LOW);
|
||||
digitalWrite(M4EN, LOW);
|
||||
GPIOB->ODR &= _OUT0[2];
|
||||
GPIOB->ODR &= _OUT0[3];
|
||||
extraMotorsInitialized = true;
|
||||
}
|
||||
|
||||
void ao() {
|
||||
m(1, 0);
|
||||
m(2, 0);
|
||||
m(3, 0);
|
||||
m(4, 0); }
|
||||
|
||||
void m(int num, int pow) {
|
||||
int id = num - 1;
|
||||
|
||||
if (!extraMotorsInitialized) initExtraMotors();
|
||||
|
||||
if (pow >= 0)
|
||||
GPIOB->ODR &= _OUT0[id];
|
||||
else
|
||||
GPIOB->ODR |= _OUT1[id];
|
||||
|
||||
analogWrite(_EN[id], min((abs(pow) * 255) / 100, 255)); }
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef EXTRA_MOTORS
|
||||
#ifdef NO_MOTOR
|
||||
#error "Extra motors module cannot be used when motor control is disabled"
|
||||
#endif
|
||||
|
||||
#define M3DIR PB13
|
||||
#define M4DIR PB12
|
||||
#define M3EN PA10
|
||||
#define M4EN PB4
|
||||
|
||||
void ao();
|
||||
void m(int num, int pow);
|
||||
|
||||
#endif // EXTRA_MOTORS
|
||||
|
||||
|
||||
#ifdef EXTRA_ALIASES
|
||||
#define a analogRead
|
||||
#define d digitalRead
|
||||
#define p pinMode
|
||||
#define o digitalWrite
|
||||
#define b beep
|
||||
#define sl(x) motor(-x, x)
|
||||
#define sr(x) motor(x, -x)
|
||||
#define tl(x) motor(0, x)
|
||||
#define tr(x) motor(x, 0)
|
||||
#define fd motor
|
||||
#define fd2 motor
|
||||
#define bk(x) motor(-x, -x)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_EXTRA_BUTTONS
|
||||
#define ok() (analogRead(9) < 16)
|
||||
#define sw_A() !digitalRead(PC13)
|
||||
#define sw_B() digitalRead(PB2)
|
||||
|
||||
#define wait_OK() while (!ok()) { delay(1); }
|
||||
#define wait_A() while (!sw_A()) { delay(1); }
|
||||
#define wait_B() while (!sw_B()) { delay(1); }
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "mp32.h"
|
||||
|
||||
#ifndef NO_MOTOR
|
||||
#define __M1DIR_OUT0 GPIOB->ODR &= 0x7FFF
|
||||
#define __M1DIR_OUT1 GPIOB->ODR |= 0x8000
|
||||
#define __M2DIR_OUT0 GPIOB->ODR &= 0xBFFF
|
||||
#define __M2DIR_OUT1 GPIOB->ODR |= 0x4000
|
||||
|
||||
static bool motorInitialized = false;
|
||||
|
||||
void initMotor() {
|
||||
motorInitialized = true;
|
||||
pinMode(M1DIR, OUTPUT);
|
||||
pinMode(M2DIR, OUTPUT);
|
||||
pinMode(M1EN, OUTPUT);
|
||||
pinMode(M2EN, OUTPUT);
|
||||
digitalWrite(M1EN, LOW);
|
||||
digitalWrite(M2EN, LOW);
|
||||
__M1DIR_OUT0;
|
||||
__M2DIR_OUT0;
|
||||
}
|
||||
|
||||
void motor(int powl, int powr) {
|
||||
if (!motorInitialized) initMotor();
|
||||
if (powl >= 0) __M1DIR_OUT0; else __M1DIR_OUT1;
|
||||
if (powr >= 0) __M2DIR_OUT0; else __M2DIR_OUT1;
|
||||
analogWrite(M1EN, min((abs(powl) * 255) / 100, 255));
|
||||
analogWrite(M2EN, min((abs(powr) * 255) / 100, 255));
|
||||
}
|
||||
|
||||
void motor(int pow) { motor(pow, pow); }
|
||||
void motor() { motor(0, 0); }
|
||||
#endif // NO_MOTOR
|
||||
|
||||
|
||||
void OK() {
|
||||
if (millis() < 200) delay(200 - millis());
|
||||
while (analogRead(9) > 16);
|
||||
while (analogRead(9) <= 16);
|
||||
}
|
||||
|
||||
void beep(int time) {
|
||||
analogWrite(PB5, 100);
|
||||
delay(time);
|
||||
analogWrite(PB5, 0);
|
||||
}
|
||||
void beep() { beep(100); }
|
||||
|
||||
// Optional OLED
|
||||
#if __has_include(<OLED_I2C_SSD1309.h>) && !defined(NO_OLED)
|
||||
#include <OLED_I2C_SSD1309.h>
|
||||
#define OLED_RESET -1
|
||||
static OLED_I2C_SSD1309 oled(OLED_RESET);
|
||||
#define OLED
|
||||
#else
|
||||
#warning "OLED_I2C_SSD1309.h not found, oled will not be initialized"
|
||||
#endif
|
||||
|
||||
void initVariant() {
|
||||
#ifndef NO_MOTOR
|
||||
initMotor();
|
||||
#endif
|
||||
analogReadResolution(12);
|
||||
pinMode(PB5, OUTPUT);
|
||||
|
||||
#ifdef OLED
|
||||
Wire.setSDA(PB9);
|
||||
Wire.setSCL(PB8);
|
||||
Wire.begin();
|
||||
oled.begin(SSD1309_SWITCHCAPVCC, 0x3C);
|
||||
oled.clear();
|
||||
oled.show();
|
||||
#endif
|
||||
|
||||
#ifdef EXTRA_MOTORS
|
||||
pinMode(9, INPUT);
|
||||
pinMode(M3DIR, OUTPUT);
|
||||
pinMode(M4DIR, OUTPUT);
|
||||
pinMode(M3EN, OUTPUT);
|
||||
pinMode(M4EN, OUTPUT);
|
||||
digitalWrite(M3EN, LOW);
|
||||
digitalWrite(M4EN, LOW);
|
||||
#endif
|
||||
|
||||
#ifndef NO_EXTRA_BUTTONS
|
||||
pinMode(PC13, INPUT_PULLUP);
|
||||
pinMode(PB2, INPUT_PULLDOWN);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#ifndef POP64
|
||||
#define POP64
|
||||
|
||||
#include "Extra.h"
|
||||
|
||||
#define a(pin) analogRead(pin)
|
||||
|
||||
// Motor control
|
||||
#ifndef NO_MOTOR
|
||||
#define M1DIR PB15
|
||||
#define M2DIR PB14
|
||||
#define M1EN PA9
|
||||
#define M2EN PA8
|
||||
|
||||
void initMotor();
|
||||
void motor(int powl, int powr);
|
||||
void motor(int pow);
|
||||
void motor();
|
||||
#endif
|
||||
|
||||
// Utility
|
||||
void OK();
|
||||
void beep(int time);
|
||||
void beep();
|
||||
|
||||
// Variant init
|
||||
void initVariant();
|
||||
|
||||
#endif // POP64
|
||||
Reference in New Issue
Block a user