Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port m5card #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 9 additions & 4 deletions doomgeneric/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ else
endif


CC=clang # gcc or g++
CC=clang++ # gcc or g++
CFLAGS+=-ggdb3 -Os
LDFLAGS+=-Wl,--gc-sections
CFLAGS+=-ggdb3 -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE # -DUSEASM
LIBS+=-lm -lc -lX11
CFLAGS+=-ggdb3 -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE -x c++ # -DUSEASM
CFLAGS+=-Ilibs/M5Cardputer-1.0.2/src -Ilibs/M5Cardputer-1.0.2/src/utility -Ilibs/M5Unified-0.1.14/src -Ilibs/M5Unified-0.1.14/src/utility -Ilibs/M5GFX-0.1.15/src
LIBS+=-lm -lc -lX11 -lM5Cardputer -lM5Unified -lM5GFX

# subdirectory for objects
OBJDIR=build
OUTPUT=doomgeneric

SRC_DOOM = dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric.o doomgeneric_xlib.o
SRC_DOOM = dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric_m5card.o
OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))

all: $(OUTPUT)
Expand All @@ -49,6 +50,10 @@ $(OBJDIR)/%.o: %.c
@echo [Compiling $<]
$(VB)$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/doomgeneric_m5card.o: doomgeneric_m5card.cpp
@echo [Compiling $<]
$(VB)$(CC) $(CFLAGS) -c $< -o $@

print:
@echo OBJS: $(OBJS)

44 changes: 44 additions & 0 deletions doomgeneric/doomgeneric_m5card.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "doomgeneric.h"
#include <M5Cardputer.h>
#include <M5Unified.h>
#include <M5GFX.h>

void DG_Init() {
M5.begin();
// Initialize M5Stack Cardputer
}

void DG_DrawFrame() {
M5.Lcd.drawBitmap(0, 0, DOOMGENERIC_RESX, DOOMGENERIC_RESY, (uint16_t*)DG_ScreenBuffer);
}

void DG_SleepMs(uint32_t ms) {
delay(ms);
}

uint32_t DG_GetTicksMs() {
return millis();
}

int DG_GetKey(int* pressed, unsigned char* key) {
*pressed = 0;
*key = 0;

if(M5.BtnA.wasPressed()) {
*pressed = 1;
*key = KEY_ENTER;
return 1;
}
else if(M5.BtnB.wasPressed()) {
*pressed = 1;
*key = KEY_FIRE;
return 1;
}
else if(M5.BtnC.wasPressed()) {
*pressed = 1;
*key = KEY_USE;
return 1;
}

return 0;
}
12 changes: 12 additions & 0 deletions doomgeneric/libs/M5Cardputer-1.0.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# M5Cardputer

## Basic library for M5Stack M5Cardputer Board


License
----------------
M5GFX : [MIT](https://github.com/m5stack/M5GFX/blob/master/LICENSE)
M5Unified : [MIT](https://github.com/m5stack/M5Unified/blob/master/LICENSE)


Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file button.ino
* @author SeanKwok ([email protected])
* @brief M5Cardputer Button Test
* @version 0.1
* @date 2023-10-09
*
*
* @Hardwares: M5Cardputer
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5GFX: https://github.com/m5stack/M5GFX
* M5Unified: https://github.com/m5stack/M5Unified
*/

#include "M5Cardputer.h"

void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg);
M5Cardputer.Display.setRotation(1);
M5Cardputer.Display.setTextColor(GREEN);
M5Cardputer.Display.setTextDatum(middle_center);
M5Cardputer.Display.setTextFont(&fonts::Orbitron_Light_32);
M5Cardputer.Display.setTextSize(1);
M5Cardputer.Display.drawString("Button Test",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2);
}

void loop() {
M5Cardputer.update();
if (M5Cardputer.BtnA.wasPressed()) {
M5Cardputer.Speaker.tone(8000, 20);
M5Cardputer.Display.clear();
M5Cardputer.Display.drawString("Pressed",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2);
}
if (M5Cardputer.BtnA.wasReleased()) {
M5Cardputer.Speaker.tone(8000, 20);
M5Cardputer.Display.clear();
M5Cardputer.Display.drawString("Released",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file buzzer.ino
* @author SeanKwok ([email protected])
* @brief M5Cardputer Buzzer Test
* @version 0.1
* @date 2023-10-09
*
*
* @Hardwares: M5Cardputer
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5GFX: https://github.com/m5stack/M5GFX
* M5Unified: https://github.com/m5stack/M5Unified
*/
#include "M5Cardputer.h"

void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg);
M5Cardputer.Display.setRotation(1);
M5Cardputer.Display.setTextColor(GREEN);
M5Cardputer.Display.setTextDatum(middle_center);
M5Cardputer.Display.setTextFont(&fonts::Orbitron_Light_32);
M5Cardputer.Display.setTextSize(1);
M5Cardputer.Display.drawString("Buzzer Test",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2);
}

void loop() {
M5Cardputer.Speaker.tone(10000, 100);
delay(1000);
M5Cardputer.Speaker.tone(4000, 20);
delay(1000);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file display.ino
* @author SeanKwok ([email protected])
* @brief M5Cardputer Display Test
* @version 0.1
* @date 2023-10-09
*
*
* @Hardwares: M5Cardputer
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5GFX: https://github.com/m5stack/M5GFX
* M5Unified: https://github.com/m5stack/M5Unified
*/
#include "M5Cardputer.h"

void draw_function(LovyanGFX* gfx) {
int x = rand() % gfx->width();
int y = rand() % gfx->height();
int r = (gfx->width() >> 4) + 2;
uint16_t c = rand();
gfx->fillRect(x - r, y - r, r * 2, r * 2, c);
}

void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg);
int textsize = M5Cardputer.Display.height() / 60;
if (textsize == 0) {
textsize = 1;
}
M5Cardputer.Display.setTextSize(textsize);
}

void loop() {
int x = rand() % M5Cardputer.Display.width();
int y = rand() % M5Cardputer.Display.height();
int r = (M5Cardputer.Display.width() >> 4) + 2;
uint16_t c = rand();
M5Cardputer.Display.fillCircle(x, y, r, c);
draw_function(&M5Cardputer.Display);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @file ir_nec.ino
* @author SeanKwok ([email protected])
* @brief M5Cardputer IR NEC test
* @version 0.1
* @date 2023-10-13
*
*
* @Hardwares: M5Cardputer
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5GFX: https://github.com/m5stack/M5GFX
* M5Unified: https://github.com/m5stack/M5Unified
* IRremote: https://github.com/Arduino-IRremote/Arduino-IRremote
*/

#define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each
// send. Saves 450 bytes program memory and
// 269 bytes RAM if receiving functions are
// not used.
#define SEND_PWM_BY_TIMER
#define IR_TX_PIN 44

#include "M5Cardputer.h"
#include <IRremote.hpp> // include the library

uint8_t sCommand = 0x34;
uint8_t sRepeats = 0;

void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg, true);
M5Cardputer.Display.setRotation(1);
M5Cardputer.Display.setTextColor(GREEN);
M5Cardputer.Display.setTextDatum(middle_center);
M5Cardputer.Display.setTextFont(&fonts::Orbitron_Light_24);
M5Cardputer.Display.setTextSize(1);

IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin
IrSender.setSendPin(IR_TX_PIN);
}

void loop() {
Serial.println();
Serial.print(F("Send now: address=0x1111, command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();

M5Cardputer.Display.clear();
M5Cardputer.Display.drawString("IR NEC SEND",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2 - 40);

M5Cardputer.Display.drawString("ADDR:0x1111",
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2);

M5Cardputer.Display.drawString("CMD:0x" + String(sCommand, HEX),
M5Cardputer.Display.width() / 2,
M5Cardputer.Display.height() / 2 + 40);

Serial.println(F("Send standard NEC with 16 bit address"));

M5Cardputer.Display.fillCircle(32, 105, 8, GREEN);
IrSender.sendNEC(0x1111, sCommand, sRepeats);
// IrSender.sendOnkyo(0x1111, 0x2223, sRepeats);
/*
* Increment send values
*/
sCommand += 1;
delay(500);
M5Cardputer.Display.fillCircle(32, 105, 8, YELLOW);
delay(500);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @file inputText.ino
* @author SeanKwok ([email protected])
* @brief M5Cardputer input text test
* @version 0.1
* @date 2023-10-13
*
*
* @Hardwares: M5Cardputer
* @Platform Version: Arduino M5Stack Board Manager v2.0.7
* @Dependent Library:
* M5GFX: https://github.com/m5stack/M5GFX
* M5Unified: https://github.com/m5stack/M5Unified
*/

#include "M5Cardputer.h"
#include "M5GFX.h"

M5Canvas canvas(&M5Cardputer.Display);
String data = "> ";

void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg, true);
M5Cardputer.Display.setRotation(1);
M5Cardputer.Display.setTextSize(0.5);
M5Cardputer.Display.drawRect(0, 0, M5Cardputer.Display.width(),
M5Cardputer.Display.height() - 28, GREEN);
M5Cardputer.Display.setTextFont(&fonts::FreeSerifBoldItalic18pt7b);

M5Cardputer.Display.fillRect(0, M5Cardputer.Display.height() - 4,
M5Cardputer.Display.width(), 4, GREEN);

canvas.setTextFont(&fonts::FreeSerifBoldItalic18pt7b);
canvas.setTextSize(0.5);
canvas.createSprite(M5Cardputer.Display.width() - 8,
M5Cardputer.Display.height() - 36);
canvas.setTextScroll(true);
canvas.println("Press Key and Enter to Input Text");
canvas.pushSprite(4, 4);
M5Cardputer.Display.drawString(data, 4, M5Cardputer.Display.height() - 24);
}

void loop() {
M5Cardputer.update();
if (M5Cardputer.Keyboard.isChange()) {
if (M5Cardputer.Keyboard.isPressed()) {
Keyboard_Class::KeysState status = M5Cardputer.Keyboard.keysState();

for (auto i : status.word) {
data += i;
}

if (status.del) {
data.remove(data.length() - 1);
}

if (status.enter) {
data.remove(0, 2);
canvas.println(data);
canvas.pushSprite(4, 4);
data = "> ";
}

M5Cardputer.Display.fillRect(0, M5Cardputer.Display.height() - 28,
M5Cardputer.Display.width(), 25,
BLACK);

M5Cardputer.Display.drawString(data, 4,
M5Cardputer.Display.height() - 24);
}
}
}
Loading