Skip to content

Commit 38c5853

Browse files
committed
added clang format
1 parent ffce431 commit 38c5853

13 files changed

+893
-948
lines changed

pawos.ino

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1+
#include <Adafruit_SPIFlash.h>
2+
#include <Adafruit_TinyUSB.h>
13
#include <Arduino.h>
4+
#include <FatLib/FatFileSystem.h>
5+
#include <SPI.h>
26
#include <WInterrupts.h>
37
#include <wiring_private.h>
4-
#include <SPI.h>
5-
#include <Adafruit_TinyUSB.h>
6-
#include <Adafruit_SPIFlash.h>
7-
#include <FatLib/FatFileSystem.h>
88

9-
#include "src/lib/PawPet_FlashTransport.h"
109
#include "src/lib/ArduinoLowPower.h"
10+
#include "src/lib/PawPet_FlashTransport.h"
1111

12+
#include "src/common.h"
1213
#include "src/config.h"
1314
#include "src/global.h"
14-
#include "src/common.h"
1515
#include "src/states/gamestate.h"
1616

1717
// TODO: Move setup of all devices elsewhere
1818
// have the .ino to contain the core update loop only
1919

20-
static const SPIFlash_Device_t possible_devices[] = {
21-
MX25R1635F
22-
};
20+
static const SPIFlash_Device_t possible_devices[] = {MX25R1635F};
2321

2422
SPIClass dispSPI(&sercom4, SHARP_MISO, SHARP_SCK, SHARP_MOSI, SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0);
2523

@@ -66,17 +64,14 @@ void setup(void)
6664

6765
// Disable 8mhz GLCK 3 that bootloader has setup, unused?
6866
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_GEN_GCLK3;
69-
while (GCLK->STATUS.bit.SYNCBUSY)
70-
;
67+
while (GCLK->STATUS.bit.SYNCBUSY) {}
7168

7269
GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(3);
73-
while (GCLK->STATUS.bit.SYNCBUSY)
74-
;
70+
while (GCLK->STATUS.bit.SYNCBUSY) {}
7571

7672
// disable DAC clock
7773
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(GCM_DAC);
78-
while (GCLK->STATUS.bit.SYNCBUSY)
79-
;
74+
while (GCLK->STATUS.bit.SYNCBUSY) {}
8075

8176
// power manager
8277
// disable unused counters
@@ -164,8 +159,7 @@ void setup(void)
164159

165160
#ifdef DEBUG
166161
// wait for serial to attach
167-
while (!Serial)
168-
;
162+
while (!Serial) {}
169163

170164
// dump registers for debugging power settings
171165
ZeroRegOptions opts = {Serial, false};
@@ -195,7 +189,7 @@ void loop(void)
195189
{
196190
//// UPDATE ////
197191
keysPressed |= readButtons();
198-
192+
199193
currentTimeMs = millis();
200194

201195
if (keysPressed)
@@ -211,30 +205,29 @@ void loop(void)
211205

212206
g::keyPressed = keysPressed;
213207
g::keyReleased = ~(prevKeysPressed) & (keysPressed);
214-
208+
215209
GameState *nextState = currentState->update();
216210

217211
if (nextState != currentState)
218212
{
219213
delete currentState;
220214
currentState = nextState;
221215

222-
switch(nextState->tick)
216+
switch (nextState->tick)
223217
{
224-
case k_tickTime30:
218+
case k_tickTime30:
225219
requestedFpsSleep = k_30_fpsSleepMs;
226220
break;
227-
case k_tickTime15:
221+
case k_tickTime15:
228222
requestedFpsSleep = k_15_fpsSleepMs;
229223
break;
230-
case k_tickTime5:
224+
case k_tickTime5:
231225
requestedFpsSleep = k_5_fpsSleepMs;
232226
break;
233-
case k_tickTime1:
227+
case k_tickTime1:
234228
requestedFpsSleep = k_1_fpsSleepMs;
235229
break;
236230
}
237-
238231
}
239232

240233
// display is done with dma transfer

src/common.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include <Arduino.h>
43
#include "config.h"
4+
#include <Arduino.h>
55

6-
#define PETPIC( x ) x, x##_meta
6+
#define PETPIC(x) x, x##_meta
77

88
typedef const uint32_t image_t;
99
typedef const uint16_t meta_t;
@@ -12,10 +12,10 @@ struct ImageMeta
1212
{
1313
uint16_t width;
1414
uint16_t height;
15-
uint16_t alpha; // has alpha channel
16-
uint16_t encoding; // true: span encoded, false: bitmap
17-
uint16_t tileCount; // number of tiles
18-
uint16_t tileOffset; // array of offsets to start of each tile
15+
uint16_t alpha; // has alpha channel
16+
uint16_t encoding; // true: span encoded, false: bitmap
17+
uint16_t tileCount; // number of tiles
18+
uint16_t tileOffset; // array of offsets to start of each tile
1919
};
2020

2121
#define PET_WHITE 0
@@ -30,47 +30,47 @@ struct ImageMeta
3030

3131
enum ButtonFlags
3232
{
33-
BUTTON_A = 0x1,
34-
BUTTON_B = 0x2,
35-
BUTTON_C = 0x4,
36-
BUTTON_P = 0x8,
33+
BUTTON_A = 0x1,
34+
BUTTON_B = 0x2,
35+
BUTTON_C = 0x4,
36+
BUTTON_P = 0x8,
3737

38-
UP = 0x10,
39-
DOWN = 0x20,
40-
LEFT = 0x40,
41-
RIGHT = 0x80,
38+
UP = 0x10,
39+
DOWN = 0x20,
40+
LEFT = 0x40,
41+
RIGHT = 0x80,
4242

43-
END = 0x100
43+
END = 0x100
4444
};
4545

4646
extern "C" char *sbrk(int i);
4747

4848
class Util
4949
{
50-
public:
51-
inline static int batteryLevel()
52-
{
53-
while (ADC->STATUS.bit.SYNCBUSY == 1);
54-
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val; // Gain Factor Selection
55-
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference
50+
public:
51+
inline static int batteryLevel()
52+
{
53+
while (ADC->STATUS.bit.SYNCBUSY == 1) {}
54+
ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_DIV2_Val; // Gain Factor Selection
55+
ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_INT1V_Val; // 1.0V voltage reference
5656

57-
float vbat = analogRead(PIN_VBAT);
58-
//return (int)vbat;
59-
vbat *= 2; // we divided by 2, so multiply back
60-
vbat *= 2.0; // Multiply by 2.0V, our reference voltage
61-
vbat /= 4096.0; // convert to voltage
62-
return vbat * 100;
63-
}
57+
float vbat = analogRead(PIN_VBAT);
58+
// return (int)vbat;
59+
vbat *= 2; // we divided by 2, so multiply back
60+
vbat *= 2.0; // Multiply by 2.0V, our reference voltage
61+
vbat /= 4096.0; // convert to voltage
62+
return vbat * 100;
63+
}
6464

65-
static int32_t FreeRam()
66-
{
67-
char stack_dummy = 0;
68-
return &stack_dummy - sbrk(0);
69-
}
65+
static int32_t FreeRam()
66+
{
67+
char stack_dummy = 0;
68+
return &stack_dummy - sbrk(0);
69+
}
7070
};
7171

7272
struct Point2D
7373
{
74-
int16_t x;
75-
int16_t y;
74+
int16_t x;
75+
int16_t y;
7676
};

src/config.h

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,50 @@
77

88
#define M0_VER_5 1
99

10-
const unsigned char BUILD_STRING[]
11-
{
12-
__TIME__[0],
13-
__TIME__[1],
14-
__TIME__[3],
15-
__TIME__[4],
16-
__DATE__[0],
17-
__DATE__[1],
18-
__DATE__[2],
19-
__DATE__[4],
20-
__DATE__[5],
21-
'\0'
22-
};
10+
const unsigned char BUILD_STRING[]{__TIME__[0], __TIME__[1], __TIME__[3], __TIME__[4], __DATE__[0],
11+
__DATE__[1], __DATE__[2], __DATE__[4], __DATE__[5], '\0'};
2312

2413
#define DISP_WIDTH 128
2514
#define DISP_HEIGHT 128
2615

2716
#if defined(M0_VER_5) || defined(M0_VER_6)
28-
// 0 RX
29-
// 1 TX
30-
#define FLASH_MISO 2 // PORTA, 14
31-
#define FLASH_SCK 3 // PORTA, 9
32-
#define FLASH_MOSI 4 // PORTA, 8
33-
#define PIN_BUTTON_C 5
34-
#define PIN_RIGHT 6
35-
#define PIN_LEFT 7
36-
#define SHARP_SS 8
37-
#define PIN_VBAT 9 // A7
38-
#define PIN_BUTTON_A 10
39-
#define PIN_BUTTON_P 11
40-
#define PIN_DOWN 12
41-
#define PIN_BUTTON_B 13
42-
// 14 A0
43-
#define PIN_BEEPER 15 // A1
44-
// 16 A2
45-
// 17 A3
46-
// 18 A4
47-
#define PIN_UP 19 // A5
48-
// SDA 20 no pullup?
49-
// SCL 21 no pullup?
50-
#define SHARP_MISO 22 // MISO
51-
#define SHARP_MOSI 23 // MOSI
52-
#define SHARP_SCK 24 // SCK
53-
#define FLASH_CS 38 // PORTA, 13
54-
55-
#define RAM_SIZE 32000
56-
57-
#define DISP_ROTATION 1
17+
// 0 RX
18+
// 1 TX
19+
#define FLASH_MISO 2 // PORTA, 14
20+
#define FLASH_SCK 3 // PORTA, 9
21+
#define FLASH_MOSI 4 // PORTA, 8
22+
#define PIN_BUTTON_C 5
23+
#define PIN_RIGHT 6
24+
#define PIN_LEFT 7
25+
#define SHARP_SS 8
26+
#define PIN_VBAT 9 // A7
27+
#define PIN_BUTTON_A 10
28+
#define PIN_BUTTON_P 11
29+
#define PIN_DOWN 12
30+
#define PIN_BUTTON_B 13
31+
// 14 A0
32+
#define PIN_BEEPER 15 // A1
33+
// 16 A2
34+
// 17 A3
35+
// 18 A4
36+
#define PIN_UP 19 // A5
37+
// SDA 20 no pullup?
38+
// SCL 21 no pullup?
39+
#define SHARP_MISO 22 // MISO
40+
#define SHARP_MOSI 23 // MOSI
41+
#define SHARP_SCK 24 // SCK
42+
#define FLASH_CS 38 // PORTA, 13
43+
44+
#define RAM_SIZE 32000
45+
46+
#define DISP_ROTATION 1
5847
#endif
5948

60-
#define MX25R1635F \
61-
{ \
62-
.total_size = (1 << 21), /* 2 MB / 16 Mb */ \
63-
.start_up_time_us = 800, .manufacturer_id = 0xc2, \
64-
.memory_type = 0x28, .capacity = 0x15, .max_clock_speed_mhz = 33 /*8*/, \
65-
.quad_enable_bit_mask = 0x40, .has_sector_protection = false, \
66-
.supports_fast_read = true, .supports_qspi = true, \
67-
.supports_qspi_writes = true, .write_status_register_split = false, \
68-
.single_status_byte = true, \
69-
}
70-
71-
72-
49+
#define MX25R1635F \
50+
{ \
51+
.total_size = (1 << 21), /* 2 MB / 16 Mb */ \
52+
.start_up_time_us = 800, .manufacturer_id = 0xc2, .memory_type = 0x28, .capacity = 0x15, \
53+
.max_clock_speed_mhz = 33 /*8*/, .quad_enable_bit_mask = 0x40, .has_sector_protection = false, \
54+
.supports_fast_read = true, .supports_qspi = true, .supports_qspi_writes = true, \
55+
.write_status_register_split = false, .single_status_byte = true, \
56+
}

src/global.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "global.h"
2-
#include <FatLib/FatFileSystem.h>
32
#include "graphics/graphic_manager.h"
3+
#include <FatLib/FatFileSystem.h>
44

55
namespace g
66
{
7-
FatFileSystem g_fatfs;
8-
GraphicCache* g_cache;
9-
uint32_t keyReleased;
10-
uint32_t keyPressed;
11-
}
7+
FatFileSystem g_fatfs;
8+
GraphicCache *g_cache;
9+
uint32_t keyReleased;
10+
uint32_t keyPressed;
11+
} // namespace g

src/global.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/**
55
* Global objects and constants
6-
*
6+
*
77
*/
88

99
constexpr uint32_t k_sleepTimeMs = 1 * 60 * 1000; // 1 minute sleep
@@ -16,8 +16,8 @@ constexpr uint32_t k_1_fpsSleepMs = 1000; // 1 fps
1616
// ticks per update, arbitrary tick rate that should scale across fps
1717
// leave overhead for 60 fps mode if possible
1818

19-
constexpr uint32_t k_tickTime30 = 2; // k_frameSleepTimeMs / 16; 30 fps ticks
20-
constexpr uint32_t k_tickTime15 = 4; // k_frameSleepTimeMs / 16; 15 fps ticks
19+
constexpr uint32_t k_tickTime30 = 2; // k_frameSleepTimeMs / 16; 30 fps ticks
20+
constexpr uint32_t k_tickTime15 = 4; // k_frameSleepTimeMs / 16; 15 fps ticks
2121
constexpr uint32_t k_tickTime5 = 13; // k_frameSleepTimeMs / 16; 5 fps ticks
2222
constexpr uint32_t k_tickTime1 = 63; // k_frameSleepTimeMs / 16; 1 fps ticks
2323

@@ -26,14 +26,14 @@ class GraphicCache;
2626

2727
namespace g
2828
{
29-
extern FatFileSystem g_fatfs;
30-
extern GraphicCache *g_cache;
31-
static struct
32-
{
33-
uint32_t flashSize;
34-
uint8_t filesysFound : 1;
35-
} stats;
36-
37-
extern uint32_t keyReleased;
38-
extern uint32_t keyPressed;
39-
}
29+
extern FatFileSystem g_fatfs;
30+
extern GraphicCache *g_cache;
31+
static struct
32+
{
33+
uint32_t flashSize;
34+
uint8_t filesysFound : 1;
35+
} stats;
36+
37+
extern uint32_t keyReleased;
38+
extern uint32_t keyPressed;
39+
} // namespace g

src/graphics/graphic_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GraphicCache
2525
static CacheEntry gcache[GRAPHIC_CACHE_COUNT];
2626
static uint16_t gindex;
2727

28-
public:
28+
public:
2929
GraphicCache();
3030

3131
int32_t LoadGraphic(const char *name);

0 commit comments

Comments
 (0)